我有一个ListBox
包含CheckBox
es 的 WPF。当 ViewModel 注意到绑定值现在已更新时,我希望 的文本颜色TextBox
变为红色。我有以下 XAML,但它不工作。我可以看到IsUpdated
正在查询的属性,但是当值为True
颜色时,颜色没有改变。我确定我遗漏了一些明显但无法弄清楚的东西。
<ListBox MinHeight="100" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border Padding="2" SnapsToDevicePixels="true">
<CheckBox x:Name="_checkBox" IsChecked="{Binding Path=IsAllowed}" Content="{Binding Item}"/>
</Border>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsUpdated}" Value="True">
<Setter TargetName="_checkBox" Property="Foreground" Value="Red"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>