is there any way that I change a Label's behavior to support toggling by click -in WPF? i.e. that's "Selector.IsSelected" property toggle between "True" and "False" by clicking. Regards.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
<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>
Note that the above template does not alter the appearance of the label based on whether it's checked or not. That might be something you'll need - hard to say without more information.
回答2:
You would better use Checkbox for such behaviour and style it to your liking.
Remember controls in WPF represent behaviours not looks.
回答3:
Just want to add the way more simple solution of mikelt21 in the duplicate post:
<CheckBox>
<Label Content="Your text here"/>
</CheckBox>