uwp:如何根据它的值更改listview项目的背景颜色?(uwp: how to change background color of listview item based on its value?)
编辑:UWP应用程序不是100%像WPF应用程序一样。
我有一个ListView的uwp应用程序。 在ListView中,我使用了DataTemplate和Tests类。 它显示测试和点的名称。
我想要完成的是一个触发器! 检查点是否大于:50,然后将ListViewItem 的背景颜色更改为红色。
<ListView.ItemTemplate> <DataTemplate x:DataType="data:Tests"> <Grid> <TextBlock Text="{x:Bind Name}" /> <TextBlock Text="{x:Bind Points}" /> </Grid> </DataTemplate> </ListView.ItemTemplate>Edit: UWP App is not 100% the same like the WPF App.
I have a uwp App with a ListView. In the ListView i use a DataTemplate with the class of Tests. It displays the name of the Test and Points.
What i want to accomplish is that a Trigger !? checks if the Points are greater than i.e.: 50 and then change the background color of the ListViewItem to red.
<ListView.ItemTemplate> <DataTemplate x:DataType="data:Tests"> <Grid> <TextBlock Text="{x:Bind Name}" /> <TextBlock Text="{x:Bind Points}" /> </Grid> </DataTemplate> </ListView.ItemTemplate>最满意答案
你可以用几种方法来做到这一点:
使用ItemContrainerStyleSelector :我找到的示例 使用DataTemplateSelector :我找到的示例 使用Converter :我发现的示例将bool描述为可见性,但您可以根据需要更改它。You can do this in several ways:
Use ItemContrainerStyleSelector: the sample which I found Use DataTemplateSelector: the sample which I found Use Converter: the sample which I found describes bool to visibility, but you can change it like you want.更多推荐
发布评论