Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is CheckBox.IsChecked property Nullable<bool>?

Tags:

c#

checkbox

wpf

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?

like image 562
gillyb Avatar asked Dec 25 '10 10:12

gillyb


5 Answers

Yes the null value exists and appears as a filled box. It indicates "Not Applicable" to the system.alt text

like image 175
mihsathe Avatar answered Oct 03 '22 12:10

mihsathe


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

 CheckBox states

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.

like image 36
Cody Gray Avatar answered Oct 01 '22 12:10

Cody Gray


Checkboxes can have a 3rd, grayed, indeterminate state.

like image 26
fejesjoco Avatar answered Oct 05 '22 12:10

fejesjoco


Don't forget to set the checkbox's property IsThreeState to true to enable this functionality.

like image 21
lunair Avatar answered Oct 02 '22 12:10

lunair


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.

like image 41
M.Kumaran Avatar answered Oct 03 '22 12:10

M.Kumaran