通过在WPF中单击来更改标签的行为以支持切换 [英] Change a Label's behavior to support toggling by click in WPF

查看:59
本文介绍了通过在WPF中单击来更改标签的行为以支持切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过单击WPF来更改Label的行为以支持切换?

Is there any way that I change a Label's behavior to support toggling by click in WPF?

即通过点击Selector.IsSelected属性可以在"True"和"False"之间切换?

i.e. that's Selector.IsSelected property toggle between "True" and "False" by clicking?

致谢.

推荐答案

<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.

这篇关于通过在WPF中单击来更改标签的行为以支持切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆