使用复选框和单选按钮时出错 [英] error when using checkboxes and radio buttons

查看:88
本文介绍了使用复选框和单选按钮时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在使用wpf的方法中为我的复选框实现一小段代码,我收到了这个错误。



 错误  1 事件; System.Windows.Controls.Primitives.ToggleButton.Checked&只能 左侧  + =   -  =    









  public   void  test()
{

if (checkBox1.Checked)
{
MessageBox.Show( 复选框现在已选中);
}
else
{
MessageBox.Show( 复选框现在未选中);
}
}





我们非常感谢任何帮助。谢谢

解决方案

checkBox1.Checked是复选框状态更改时生成的事件。 checkBox1.IsChecked是复选框的状态。

所以要确定复选框的当前状态使用

 if(checkBox1.IsChecked)


I was trying to implement a small piece of code for my checkbox within a method using wpf, and i got this error.

"

Error   1   The event;System.Windows.Controls.Primitives.ToggleButton.Checked& can only appear on the left hand side of += or -= "





public void test()
{

if (checkBox1.Checked)
                   {
                      MessageBox.Show("checkbox is checked now");
                     }
else
{
MessageBox.Show("checkbox is unchecked now");
}
}



Any help would be much appreciated. Thanks

解决方案

checkBox1.Checked is the event which is generated when the state of the checkbox is changed. checkBox1.IsChecked is the state of the checkbox.
So to determine the current state of the checkbox use

if (checkBox1.IsChecked)


这篇关于使用复选框和单选按钮时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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