C#WPF检查复选框是否被选中错误 [英] C# WPF check if checkbox is checked error

查看:444
本文介绍了C#WPF检查复选框是否被选中错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我这样做:

  if(checkbox1.IsChecked)
pre>

我得到的错误:不能隐式转换类型'bool?'到'bool'。



我这样做:

  if(checkbox1.Checked)

我得到错误:事件System.Windows.Controls.Primitives.ToggleButton.Checked只能出现在+ =或 - =的左侧。 / p>

任何想法我做错了什么?

解决方案

IsChecked 是一个可空的布尔值,这意味着它可以有三个状态。可空类型由<$ p $ c>?表示。



请尝试:

  if((bool)checkbox1.IsChecked == true)


When I do:

if (checkbox1.IsChecked)

I get the error: Cannot implicitly convert type 'bool?' to 'bool'.

When I do:

if (checkbox1.Checked)

I get the error: "The event 'System.Windows.Controls.Primitives.ToggleButton.Checked' can only appear on the left hand side of += or -=".

Any ideas what I'm doing wrong?

解决方案

IsChecked is a nullable boolean, which means it can have three states. Nullable types are denoted by the ? you see in the error.

Try this:

if ((bool)checkbox1.IsChecked == true)

这篇关于C#WPF检查复选框是否被选中错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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