WPF:将复选框的可点击区域限制为仅限复选框

时间:2017-07-31 14:30:02

标签: c# wpf checkbox

我使用的复选框如下:

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

目前,如果我点击复选框或标签,检查状态将会改变。是否可以将此限制为仅在选中复选框时更改?

1 个答案:

答案 0 :(得分:2)

您可以将文字放在单独的TextBlock中,然后将它们包装在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>