有什么方法可以更改标签的行为以支持通过在 WPF 中单击来进行切换?
即通过单击在“真”和“假”之间切换 Selector.IsSelected
属性?
问候。
最佳答案
<StackPanel>
<CheckBox IsChecked="{Binding IsChecked, ElementName=checkbox}" Content="Hello">
<CheckBox.Template>
<ControlTemplate TargetType="CheckBox">
<ContentPresenter/>
</ControlTemplate>
</CheckBox.Template>
</CheckBox>
<CheckBox x:Name="checkbox" Content="A normal checkbox"/>
</StackPanel>
请注意,上述模板不会根据是否选中标签来改变标签的外观。这可能是您需要的东西 - 没有更多信息就很难说。
关于wpf - 更改标签的行为以支持在 WPF 中通过单击进行切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6160566/