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.