私は次のコードを持っています:
<ControlTemplate x:Key="ViewItemTemplate"
TargetType="ListViewItem">
<StackPanel Orientation="Horizontal">
<CheckBox Margin="0,0,3,0" x:Name="CkBox">
<CkBox.IsChecked>
<Binding Path="IsSelected"
Mode="TwoWay">
<Binding.RelativeSource>
<RelativeSource Mode="TemplatedParent" />
</Binding.RelativeSource>
</Binding>
</CkBox.IsChecked>
<DataTrigger Binding="{Binding InvalidForeground}" Value="true">
<Setter TargetName="CkBoxVisual" Property="Foreground" Value="#999999"/>
</DataTrigger>
</CheckBox>
<ContentPresenter />
</StackPanel>
</ControlTemplate>
InvalidForeground をバインドするにはどうすればよいですか? DataTemplate を使用するように指示する多くの例をオンラインで調べました。しかし、StackPanel の上に DataTemplate を追加すると、エラーが発生しますか? 私は何か間違ったことをしていますか?
コードを追加できるように、InvalidForeground をバインドしようとしています。エラーが表示されます: DataContext が不明なため、シンボル 'InvalidForeground' を解決できません。