uwp:如何根据它的值更改listview项目的背景颜色?(uwp: how to change background color of listview item based on its valu

编程入门 行业动态 更新时间:2024-10-23 11:23:53
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.

更多推荐

本文发布于:2023-07-05 09:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1035494.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   背景   项目   listview   uwp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!