简体   繁体   English

为什么使用`Checked`属性会导致奇怪的错误,事件只能发生在+ =或 - =的右边?

[英]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.

相关问题 为什么会发生这种奇怪的抖动? - Why does this strange jittering occur? 继续收到此错误:事件'System.Windows.Controls.Primitives.ToggleButton.Checked'只能出现在+ =或 - =的左侧 - Keep getting this error: The event 'System.Windows.Controls.Primitives.ToggleButton.Checked' can only appear on the left hand side of += or -= 为什么在使用SingleAsync时发生此错误? - Why does this error occur when using SingleAsync? 将依赖项属性添加到自定义控件会导致样式出现奇怪的错误 - Adding dependency property to custom control causes strange errors to occur to style 使用Delegate.Combine错误事件只能出现在+ =或 - =的左侧? - Using Delegate.Combine error Event can only appear on the left-hand side of += or -=? 该事件只能出现在+ =或-=错误的左侧 - The event can only appear on the left hand side of += or -= error 只有双击才会发生事件 - Only with a double click does the event occur 该事件只能出现在+ =或-=的左侧 - The event can only appear on the left hand side of += or -= 为什么TextBox.Click事件只能出现在+ =或-=的左侧 - why TextBox.Click event can only appear on the left hand side of += or -= system.threading.task - 为什么不发生TaskScheduler.UnobservedTaskException事件? 我能解决这个问题吗? - system.threading.task - why does TaskScheduler.UnobservedTaskException event not occur? Can I fix this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM