我有以下代碼:XAML代碼不工作 - C#
<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>
什麼,我想實現的就是改變複選框文本的顏色。但上面的代碼不起作用。任何人都可以幫助我嗎?從提拉克
嘗試代碼:
<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>
這不是工作?難道我做錯了什麼?
您是否嘗試直接更改CheckBox的Foreground屬性? –
@ArsenMkrt - 我如何直接更改它?我可以在代碼中執行一些操作嗎? – NoviceMe