WPF复选框检查IsChecked [英] WPF Checkbox check IsChecked

查看:535
本文介绍了WPF复选框检查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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆