我有以下代码:
<DataTemplate DataType="{x:Type abc}">
<StackPanel Orientation="Horizontal">
<CheckBox Margin="0,0,3,0" x:Name="CheckBox">
<CheckBox.IsChecked>
<Binding Path="IsSelected"
Mode="TwoWay">
<Binding.RelativeSource>
<RelativeSource Mode="Template" />
</Binding.RelativeSource>
</Binding>
</CheckBox.IsChecked>
</CheckBox>
<TextBlock Text="{Binding}"
Margin="0,0,10,5" />
<TextBlock Text="{Binding Channel}"
Margin="7,0,0,0"
Visibility="{Binding Path=IsChannelVisible,ElementName=View, Converter={StaticResource BooleanToVisibile}}" />
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Valid}" Value="true">
<Setter TargetName="CheckBox" Property="Foreground" Value="#000000"/>
</DataTrigger>
<DataTrigger Binding="{Binding Valid}" Value="false">
<Setter TargetName="CheckBox" Property="Foreground" Value="#999999"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
我想要实现的是更改复选框文本的颜色。但是上面的代码不起作用。谁能帮我解决这个问题?
来自 Tilak 的尝试代码:
<ControlTemplate x:Key="Template"
TargetType="ListViewItem">
<StackPanel Orientation="Horizontal">
<CheckBox Margin="7,0,0,0" Foreground={Binding Valid, Converter={StaticResource ValidToColorConverter}}
x:Name="CheckBox">
<CheckBox.IsChecked>
<Binding Path="IsSelected"
Mode="TwoWay">
<Binding.RelativeSource>
<RelativeSource Mode="Parent" />
</Binding.RelativeSource>
</Binding>
</CheckBox.IsChecked>
</CheckBox>
<ContentPresenter />
<DataTemplate.CheckBox>
<Intellivu:ValidToColorConverter x:Key="ValidToColorConverter" />
</DataTemplate.CheckBox>
</StackPanel>
</ControlTemplate>
这不工作?难道我做错了什么?