WPF Checkbox check IsChecked

后端 未结 8 800
别跟我提以往
别跟我提以往 2020-12-08 10:25

I\'m not talking about an event handler for this, but rather a simple If Statement checking if the CheckBox has been checked. So far I have:

<
相关标签:
8条回答
  • 2020-12-08 10:53

    Multiple answers already but here is another alternative

    if (chkRevLoop.IsChecked.GetValueOrDefault()) {}
    

    From MSDN

    0 讨论(0)
  • 2020-12-08 10:59

    A bool? can be true, false or null, while bool can only be true or false. ? makes a type "nullable" and adds null as a possibility when it normally isn't, so you can probably just use

    if ((bool)chkRevLoop.IsChecked == true){}
    

    or

    if (chkRevLoop.IsChecked == (bool?)true){}
    

    to make it match up and work. The second is probably better, since I don't know what would happen in the cast if IsChecked is null

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