RadioButton.GroupName Property
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Gets or sets the name that specifies which RadioButton controls are mutually exclusive.
Namespace: System.Windows.Controls
Assembly: System.Windows (in System.Windows.dll)
Syntax
'Declaration
Public Property GroupName As String
public string GroupName { get; set; }
<RadioButton GroupName="nameString"/>
Property Value
Type: System.String
The name that specifies which RadioButton controls are mutually exclusive. The default is nulla null reference (Nothing in Visual Basic).
Remarks
Dependency property identifier field: GroupNameProperty
When two or more RadioButton controls have the same GroupName, a user can select (check) only one RadioButton at a time, regardless of the RadioButton control's parent. If no GroupName is specified, the RadioButton are grouped with other RadioButton controls under the same parent.
Examples
The following example shows two panels that contain three radio buttons each. One radio button from each panel are grouped together. The remaining two radio buttons on each panel are not grouped explicitly, which means they are grouped together since they share the same parent control. When you run this sample and select a radio button, a TextBlock displays the name of the group, or "grouped to panel" for a radio button without an explicit group name, and the name of the radio button.
Private Sub HandleCheck(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim rb As RadioButton = TryCast(sender, RadioButton)
choiceTextBlock.Text = "You chose: " + rb.GroupName + ": " + rb.Name
End Sub
private void HandleCheck(object sender, RoutedEventArgs e)
{
RadioButton rb = sender as RadioButton;
choiceTextBlock.Text = "You chose: " + rb.GroupName + ": " + rb.Name;
}
<TextBlock Text="First Group:" Margin="5" />
<RadioButton x:Name="TopButton" Margin="5" Checked="HandleCheck"
GroupName="First Group" Content="First Choice" />
<RadioButton x:Name="MiddleButton" Margin="5" Checked="HandleCheck"
GroupName="First Group" Content="Second Choice" />
<TextBlock Text="Ungrouped:" Margin="5" />
<RadioButton x:Name="LowerButton" Margin="5" Checked="HandleCheck"
Content="Third Choice" />
<TextBlock x:Name="choiceTextBlock" Margin="5" />
Version Information
Silverlight
Supported in: 5, 4, 3
Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.