【发布时间】:2019-06-20 03:05:50
【问题描述】:
我在 listView 中有预订时间,例如 8:00、9:00 等。通过 JSON,我从远程数据库中检索已经进行的预订。所以我想将每个单元格(标签)的背景颜色更改为保留的红色,其余为绿色(免费约会)。
这是我的 xaml 代码:
<StackLayout>
<ListView x:Name="ItemsListView"
ItemsSource="{Binding Items}"
VerticalOptions="FillAndExpand"
HasUnevenRows="true"
RefreshCommand="{Binding LoadItemsCommand}"
IsPullToRefreshEnabled="true"
IsRefreshing="{Binding IsBusy, Mode=OneWay}"
CachingStrategy="RecycleElement"
ItemSelected="OnItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10">
<Label Text="{Binding Text}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="16" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
ListView 由以下模型填充:
new Termin { Id = Guid.NewGuid().ToString(), Text = "12:00", Description="" },
那么我怎样才能改变这些单元格的颜色呢?
我想要的伪代码:
for(int i=0; i< number of items in the listview; i++) {
if(reservations.contains(listview.itemAt(i)) {
//change background color of viewcell (label?) at position i
}
}
【问题讨论】:
-
如果您将模型更改为具有 IsReserved 属性会更容易。之后,在 Listview viewcell 中只有一个转换器来改变颜色,例如。
-
我太新手了,听不懂你说的一半。
标签: listview xamarin xamarin.forms background-color