uwp:如何根据值更改列表视图项的背景颜色? [英] uwp: how to change background color of listview item based on its value?

查看:38
本文介绍了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:

  1. 使用ItemContrainerStyleSelector:示例 我发现
  2. 使用DataTemplateSelector:我找到的样本
  3. 使用Converter:示例 我发现它描述了 bool 到可见性,但您可以随意更改它.
  1. Use ItemContrainerStyleSelector: the sample which I found
  2. Use DataTemplateSelector: the sample which I found
  3. Use Converter: the sample which I found describes bool to visibility, but you can change it like you want.

这篇关于uwp:如何根据值更改列表视图项的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆