Clyde Eisenbeis

Clyde Eisenbeis

  • 1.7k
  • 81
  • 13.5k

How do I set a RadioButton to true if the Content matches?

Dec 4 2024 12:07 AM

XAML

<GroupBox Name="FirstGroupBox"
            Header="1st"
            Margin="10,0,5,0"
            Height="auto"
            Width="auto"
            >
  <RadioButton x:Name="gRBuResearcher1" Content ="Researcher" Click="gRBuResearcher1_Click" />
  <RadioButton x:Name="gRBuScientist1" Content="Scientist" Click="gRBuScientist1_Click" />
  <RadioButton x:Name="gRBuMedic1" Content="Medic" Click="gRBuMedic1_Click" />
</GroupBox>

XAML.CS

using System.Windows.Controls;

foreach (var child in FirstGroupBox.Children)
{
    if (child.Content is "Scientist")
    {
        RadioButton.IsChecked = true;
    }
}

This does not work.  How do I set gRBuScientist1 to true?


Answers (1)