Share via


How to: Create RadioButton Groups

When RadioButton controls are grouped, the buttons are mutually exclusive. A user can select only one item at a time within a RadioButton group. Unlike a CheckBox, when a RadioButton is selected it cannot be cleared by clicking it. The application programmatically clears a selected item when the user selects a new item. Whether a RadioButton is selected is determined by the state of its IsChecked property. You can group RadioButton controls by placing them inside a parent or by giving them a group name. The following example groups three RadioButton elements inside a StackPanel parent.

Example

<StackPanel>      
    <RadioButton Name="rb1" Checked="WriteText2">Yes</RadioButton>
    <RadioButton Name="rb2" Checked="WriteText2">No</RadioButton>
    <RadioButton Name="rb3" Checked="WriteText2">No opinion</RadioButton>
</StackPanel>

This example uses the GroupName property to group the RadioButton controls into two groups.

<StackPanel>
    <RadioButton GroupName="colorgrp">Red</RadioButton>
    <RadioButton GroupName="colorgrp">Blue</RadioButton>
    <RadioButton GroupName="numgrp">1</RadioButton>
    <RadioButton GroupName="numgrp">2</RadioButton>
</StackPanel>

For the complete sample see RadioButton Sample.

See Also

Reference

ToggleButton

Concepts

RadioButton Overview