简体   繁体   中英

Why is IsChecked property nullable boolean in WPF CheckBox?

Is there a case when IsChecked property on WPF CheckBox null ?

I guess that will answer my question from title of question.

It is null when you don't know if its checked or not: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.togglebutton.ischecked.aspx

In many systems a checkbox like this is shaded instead of being checked.

如果真是这样,那么可能是三个状态的复选框,请参阅http://msdn.microsoft.com/zh-cn/library/system.windows.forms.checkbox.threestate.aspx进行解释。

Null表示CheckBox是不确定的(既不为空白,也不为选中状态,而是通过一行,或者该框内部有一个灰色框)

If we want to bind a value from DB and if that value is null then we have to handle that also. A boolean DB value can be True, False or NULL. So the UI checkbox also must be handle the there states. That's why WPF CheckBox has 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