我目前在制作一个网格,每个单元格中都有一个标签,标签中的内容来自使用DataBinding的列表。 我正在尝试根据标签中的值更改每个单元格的颜色。例如,如果值为1,则背景必须是黑色。 以下是我目前的代码:
<Window.Resources>
<DataTemplate x:Key="DataTemplate_Level2">
<Label Content="{Binding}" Width="70" Height="70" HorizontalContentAlignment="Center">
</Label>
</DataTemplate>
<DataTemplate x:Key="DataTemplate_Level1">
<ItemsControl ItemsSource="{Binding}" ItemTemplate="{DynamicResource DataTemplate_Level2}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
</Window.Resources>
我尝试使用触发器的不同方法,但似乎都没有起作用。
如果能得到帮助将不胜感激。
谢谢。