uwp:如何根据值更改列表视图项的背景颜色? [英] uwp: how to change background color of listview item based on its value?
本文介绍了uwp:如何根据值更改列表视图项的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
UWP 应用与 WPF 应用并非 100% 相同.
UWP App is not 100% the same like the WPF App.
我有一个带有 ListView 的 uwp 应用程序.在 ListView 中,我使用了一个 DataTemplate 和 Tests 类.它显示测试和点的名称.
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.
我想要完成的是一个触发器!?检查点数是否大于即:50,然后将 ListViewItem 的背景颜色更改为红色.
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>
推荐答案
您可以通过多种方式做到这一点:
You can do this in several ways:
- 使用
ItemContrainerStyleSelector
:示例 我发现 - 使用
DataTemplateSelector
:我找到的样本 - 使用
Converter
:示例 我发现它描述了 bool 到可见性,但您可以随意更改它.
- 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.
这篇关于uwp:如何根据值更改列表视图项的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文