Home > database >  Check Group of Radiobutton is selected or not
Check Group of Radiobutton is selected or not

Time:01-21

So i have a Group of RadioButtons in a StackPanel, now i want to check if something is selected or not.

            var programme = programm_wahl.Children.OfType<RadioButton>().FirstOrDefault(r => r.IsChecked.HasValue && r.IsChecked.Value);

        if (programme.IsChecked == true ) {..}

It is throwing me a error that programme is null i tried also programme.IsChecked != null && programme.IsChecked == true both ways not working.

CodePudding user response:

The error is shown because the programme variable is returning a null value.

Meaning the object .IsChecked is not available.

Try this:

if (programme != null && programme.IsChecked == true) {...}
  • Related