I have a group of radiobuttons (about 20) placed in different expanders.
<StackPanel>
<Expander>
<Expander.Header>
<TextBlock>Expander1</TextBlock>
</Expander.Header>
<StackPanel>
<RadioButton GroupName="G" x:Name="RadioButton1">Radiobutton1</RadioButton>
<RadioButton GroupName="G" x:Name="RadioButton2">Radiobutton2</RadioButton>
</StackPanel>
</Expander>
<Expander>
<Expander.Header>
<TextBlock>Expander2</TextBlock>
</Expander.Header>
<StackPanel>
<RadioButton GroupName="G" x:Name="RadioButton3">Radiobutton3</RadioButton>
<RadioButton GroupName="G" x:Name="RadioButton4">Radiobutton4</RadioButton>
</StackPanel>
</Expander>
<!-- ... -->
</StackPanel>
I have user controls in different xaml files and a MainWindow.xaml. Depending on a checked radiobutton a specific user control needs to be added to the main window. What is the best way to handle "Checked" event for these 20 radiobuttons? How to know which radiobutton is checked?