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)

'Declaration
Public Property GroupName As String
<RadioButton GroupName="nameString"/>

Property Value

Type: System.String
The name that specifies which RadioButton controls are mutually exclusive. The default is Nothing.

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



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

Community Additions

ADD
Show: