简体   繁体   中英

WPF Checkbox - Clicking label does not change checked state

I have a CheckBox in a TabItem Header in a WPF application. I am finding that when you click on the TabItem, it is checking the CheckBox, but not opening the TabItem. I would like only the actual CheckBox to register the click event to change the state from Checked to Unchecked or vice versa. That way, clicking on the label of the CheckBox will open the TabItem.

I've tried using an empty CheckBox that has no content and then a separate Label adjacent to it, but then the TabItem tells me that it cannot have 2 headers.

<TabItem>
    <TabItem.Header>
        <CheckBox  Name="chkExportEnabled" Content="{x:Static resources:Global.Label_Export}" IsChecked="{Binding EnableExport}"/>
    </TabItem.Header>
</TabItem>

You can just use a StackPanel with Orientation='Horizontal' around the label-less CheckBox and the Label . TabItem.Header may only contain a single child, that's why you get the error, but nothing prevents you from using layout containers as that child.

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