Check Group of Radiobutton is selected or not

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.

>Solution :

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) {...}

Leave a Reply