方案如下:
public enum DayOfWeek
{
All = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6,
Sunday = 7
}
public class Class2{
public List<DayOfWeek> DaysOfWeek
}
public class Class1{
public List<Class2> aList{get; set;}
}
我的ViewModel中有Class1,它通过BindingContext链接到View。
我想在列表中显示我目前正在做的事情。
在ListView中,我定义了一个ViewCell(内部),如:
<Grid Grid.Row="1" Grid.Column="1" HorizontalOptions="Center" VerticalOptions="Center" RowSpacing="1" ColumnSpacing="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="17"/>
<ColumnDefinition Width="17"/>
<ColumnDefinition Width="17"/>
<ColumnDefinition Width="17"/>
<ColumnDefinition Width="17"/>
<ColumnDefinition Width="17"/>
<ColumnDefinition Width="17"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="17"/>
<RowDefinition Height="17"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="M" VerticalOptions="Center" HorizontalOptions="Center"/>
<Label Grid.Row="0" Grid.Column="1" Text="T" VerticalOptions="Center" HorizontalOptions="Center"/>
<Label Grid.Row="0" Grid.Column="2" Text="W" VerticalOptions="Center" HorizontalOptions="Center"/>
<Label Grid.Row="0" Grid.Column="3" Text="T" VerticalOptions="Center" HorizontalOptions="Center"/>
<Label Grid.Row="0" Grid.Column="4" Text="F" VerticalOptions="Center" HorizontalOptions="Center"/>
<Label Grid.Row="0" Grid.Column="5" Text="S" VerticalOptions="Center" HorizontalOptions="Center"/>
<Label Grid.Row="0" Grid.Column="6" Text="S" VerticalOptions="Center" HorizontalOptions="Center"/>
<BoxView Grid.Row="1" Grid.Column="0" VerticalOptions="Center" HorizontalOptions="Center"/>
<BoxView Grid.Row="1" Grid.Column="1" VerticalOptions="Center" HorizontalOptions="Center"/>
<BoxView Grid.Row="1" Grid.Column="2" VerticalOptions="Center" HorizontalOptions="Center"/>
<BoxView Grid.Row="1" Grid.Column="3" VerticalOptions="Center" HorizontalOptions="Center"/>
<BoxView Grid.Row="1" Grid.Column="4" VerticalOptions="Center" HorizontalOptions="Center"/>
<BoxView Grid.Row="1" Grid.Column="5" VerticalOptions="Center" HorizontalOptions="Center"/>
<BoxView Grid.Row="1" Grid.Column="6" VerticalOptions="Center" HorizontalOptions="Center"/>
</Grid>
基本上我打算在盒子里显示DaysOfWeek,并将它们用红色或绿色着色,这取决于DaysOfWeek中是否有一天。
我认为设置颜色我需要使用转换器来检查列表中包含的天数(DaysOfWeek),如果是,则返回绿色,否则返回红色。这是对的吗?
我应该如何设置绑定?如何指向列表中列表的元素和元素?
目前我在使用MVVM设置绑定Class 2或Class 1的其他属性时遇到了足够的问题。
有什么想法吗?