GroupName Property
Collapse the table of content
Expand the table of content

RadioButton.GroupName Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets the name that specifies which RadioButton controls are mutually exclusive.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

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 null.

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.

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 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" />


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft