简体   繁体   中英

Why is CheckBox.IsChecked property Nullable<bool>?

Why is the IsChecked property of a checkbox control in WPF of type bool? (or Nullable<bool> ). I mean how can a checkbox control have the value of null ?

Yes the null value exists and appears as a filled box. It indicates "Not Applicable" to the system. 替代文字

According to the documentation , the IsChecked property has three different possible states:

CheckBox声明

So, when IsChecked is set to null , the check box will show an "indeterminate" state. This is commonly represented as a shaded, or greyed-out, control.

复选框可以具有第三个灰色的不确定状态。

不要忘记将复选框的属性IsThreeState设置为true以启用此功能。

Because WPF supports binding. If we bind a DB boolean column value to a checkbox. That column may have True/False/Null values. That means it has three values for a boolean field. So the WPF UI also should handle the three state.

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