Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change a Label's behavior to support toggling by click in WPF

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.

like image 371
amiry jd Avatar asked Dec 16 '22 13:12

amiry jd


1 Answers

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

like image 95
Kent Boogaart Avatar answered Feb 02 '23 01:02

Kent Boogaart