提问人:humudu 提问时间:2/3/2016 最后编辑:renehumudu 更新时间:2/19/2018 访问量:2561
C# WPF 检查复选框是否被选中错误 [重复]
C# WPF check if checkbox is checked error [duplicate]
问:
当我这样做时:
if (checkbox1.IsChecked)
我收到错误:
无法将类型“bool?”隐式转换为“bool”。
当我这样做时:
if (checkbox1.Checked)
我收到错误:
“事件'System.Windows.Controls.Primitives.ToggleButton.Checked'只能出现在+=或-=的左侧”。
知道我做错了什么吗?
答:
0赞
Sonny Childs
2/3/2016
#1
IsChecked
是一个可为 null 的布尔值,这意味着它可以有三种状态。可为 null 的类型由错误中看到的 表示。?
试试这个:
if ((bool)checkbox1.IsChecked == true)
评论