RadioButton.Checked Error: Control.Checked cannot appear on the left hand side of += or -=

前端 未结 3 1045
北荒
北荒 2021-01-06 17:21

I am having the strangest problem, and I have to be missing something.

Here is my code that is causing the error.

if (radLot.Checked == true)
{
    S         


        
相关标签:
3条回答
  • 2021-01-06 18:12

    Checked is the name of the event that is raised when a ToggleButton is checked. (The RadioButton class derives from ToggleButton.)

    I assume you want to access the IsChecked property, which gets (or sets) whether the ToggleButton is checked.

    if (radLot.IsChecked == true)
    {
        SymbolSpecification = "LotRenderer";
    }
    

    Hint: Most boolean properties related to the visual state start with Is— in WPF.

    0 讨论(0)
  • 2021-01-06 18:15

    Alternative you can check the CheckState to perform your statement.

     if (radLot.CheckState == CheckState.Checked)
                {
    
                }
    

    Edit: This will only work when writing a winform application. It will not work with WPF. Use Douglas' answer for WPF.

    0 讨论(0)
  • 2021-01-06 18:18

    This is indeed true - just hit this problem myself converting from Winforms to WPF.

    In WPF using:

    if (radiobutton1.IsChecked == true)
    

    works

    BUT

    if (radiobutton1.IsChecked)
    

    Does not.

    However in WinForms

    if (radiobutton1.Checked)
    

    works but does not in WPF.

    0 讨论(0)
提交回复
热议问题