WPF复选框检查IsChecked [英] WPF Checkbox check IsChecked
问题描述
我不是在谈论一个事件处理程序,而是一个简单的 If Statement
检查 CheckBox
已经过检查。到目前为止,我有:
I'm not talking about an event handler for this, but rather a simple If Statement
checking if the CheckBox
has been checked. So far I have:
if (chkRevLoop.IsChecked == true){}
但这会引发错误:
无法隐式转换输入'bool?'来'bool'。存在显式转换(您是否错过了演员?)
Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)
有没有办法做到这一点,我错过了?
Is there a way to do this that I'm missing?
推荐答案
您可以使用 null coalescing operator 。如果左侧操作数为空,则此运算符返回右侧操作数。因此,当 CheckBox
位于 false /en-us/library/system.windows.controls.primitives.togglebutton.ischecked(v=vs.110).aspx\"rel =nofollow noreferrer> indeterminate 状态(当 IsChecked
属性的值设置为null):
You can use null coalescing operator. This operator returns right-hand operand if the left-hand operand is null. So you can return false
when the CheckBox
is in indeterminate state (when the value of IsChecked
property is set to null):
if (chkRevLoop.IsChecked ?? false)
{
}
这篇关于WPF复选框检查IsChecked的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!