简体   繁体   English

为什么在WPF CheckBox中IsChecked属性为可空布尔值?

[英]Why is IsChecked property nullable boolean in WPF CheckBox?

Is there a case when IsChecked property on WPF CheckBox null ? WPF CheckBox上的IsChecked属性是否为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 如果您不知道是否选中它,则为null: http : //msdn.microsoft.com/zh-cn/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. 如果我们要绑定数据库中的值,并且该值为null,那么我们也必须处理该值。 A boolean DB value can be True, False or NULL. 布尔型DB值可以为True,False或NULL。 So the UI checkbox also must be handle the there states. 因此,UI复选框也必须处理那里的状态。 That's why WPF CheckBox has three state. 这就是WPF CheckBox具有三个状态的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM