简体   繁体   中英

WPF: Limit clickable area of checkbox to the checkbox only

I am using a checkbox as follows:

<CheckBox Content="Reload Code Table Rules"
          IsChecked="{Binding ReloadCodeTableRules, UpdateSourceTrigger=PropertyChanged}"
          VerticalAlignment="Center" />

Currently the checked state will change if I click on either the checkbox or the label. Is it possible to limit this to only change when the checkbox is checked?

You could place the text in a separate TextBlock and wrap them together in a StackPanel :

<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
    <CheckBox IsChecked="{Binding ReloadCodeTableRules, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center"/>
    <TextBlock Margin="4,0,0,0" Text="Reload Code Table Rules" VerticalAlignment="Center"/>
</StackPanel>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM