Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

RadioButton.GroupName Property

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

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

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


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft