RadioButton control in WPF
RadioButton:
Namespace : System.Windows.Controls.RadioButton
Designer Code:
<RadioButton Margin="10,10,0,13" Name="RadioButton1" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="180" Height="20" Background="Red"
Foreground="Orange" Checked="RadioButton1_Checked">
One
</RadioButton>
Code Behind:
// Window1.xaml.cs
private void RadioButton1_Checked(object sender,
RoutedEventArgs e)
{
bool? state = RadioButton1.IsChecked;
}
This is a ToggleButton.
Grouping of Radio Buttons:
If you want RadioButtons to participate in the same “Group” when parented to different panels, use GroupName=”myGroup”.
<StackPanel>
<RadioButton Margin="10,5,0,0" GroupName="MyGroup" Background="Orange"
Foreground="Blue" >
one
</RadioButton>
<RadioButton Margin="10,5,0,0" GroupName="MyGroup" Background="Orange"
Foreground="Red" >
Two
</RadioButton>
<RadioButton Margin="10,5,0,0" GroupName="MyGroup" Background="Orange"
Foreground="Green" >
Three
</RadioButton>
<RadioButton Margin="10,5,0,0" GroupName="MyGroup" Background="Orange"
Foreground="Pink" >
Four
</RadioButton>
</StackPanel>