[英]Why does using the `Checked` property causes strange error the event can only occur on right hand of += or -=?
I am working on c# on a WPF application.I have written the following code 我正在使用WPF应用程序上的c#。我编写了以下代码
public partial class MainWindow : Window
{
public MainWindow()
{
RadioButton daw;
InitializeComponent();
if (qoneone.Checked == true)
{
MessageBox.Show("Correct");
}
}
A error occurs that says 出现错误
event
qoneone.Checked
can only appear on left hand side of+=
or-=
事件
qoneone.Checked
只能出现在+=
或-=
左侧
You are accessing the wrong member of qoneone
. 您正在访问
qoneone
的错误成员。
Instead you have to check the boolean property qoneone.IsChecked == true
. 相反,你必须检查布尔属性
qoneone.IsChecked == true
。
IsChecked
is a property that you can read or write to get or change the current state of the RadioButton
. IsChecked
是一个属性,您可以读取或写入以获取或更改RadioButton
的当前状态。
But Checked
is an event . 但是
Checked
是一个活动 。 (You could attach an handler to it using +=
so you can do something when the RadioButton
state change. Hence the error message.) (您可以使用
+=
将处理程序附加到它,以便在RadioButton
状态更改时可以执行某些操作。因此错误消息。)
As giangregorio has stated, quone.checked
is a property and this requires an event. 正如giangregorio所说,
quone.checked
是一个属性,这需要一个事件。
What you should be doing here is a delegate: 你应该在这里做的是代表:
QueoneChanged += quoneevent;
quoneevent (Object sender, routed event s)
{
\\insert code here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.