RadioButton Class
Updated: April 2009
Represents a button that can be selected, but not cleared, by a user. The IsChecked property of a RadioButton can be set by clicking it, but it can only be cleared programmatically.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
A RadioButton has two states: true or false.
Content Model: RadioButton is a ContentControl. Its content property is Content. For more information on the content model for RadioButton, see Controls Content Model Overview.
The RadioButton is a control that is usually used as an item in a group of RadioButton controls. However, it is possible to create a single RadioButton. Whether a RadioButton is selected is determined by the state of its IsChecked property.
When a RadioButton is selected, it cannot be cleared by clicking it. When RadioButton elements are grouped, the buttons are mutually exclusive. A user can select only one item at a time within a RadioButton group. You can group RadioButton controls by placing them inside a parent or by setting the GroupName property on each RadioButton.
Dependency properties for this control might be set by the control’s default style. If a property is set by a default style, the property might change from its default value when the control appears in the application. The default style is determined by which desktop theme is used when the application is running. For more information, see Themes.
The following example shows how to create RadioButton controls, group them inside a container, and handle the Checked event.
<StackPanel> <RadioButton Name="rb1" Checked="WriteText2">Yes</RadioButton> <RadioButton Name="rb2" Checked="WriteText2">No</RadioButton> <RadioButton Name="rb3" Checked="WriteText2">No opinion</RadioButton> </StackPanel>
The following code sample creates two separate RadioButton groups: colorgrp and numgrp. The user can choose one RadioButton in each group.
<StackPanel> <RadioButton GroupName="colorgrp">Red</RadioButton> <RadioButton GroupName="colorgrp">Blue</RadioButton> <RadioButton GroupName="numgrp">1</RadioButton> <RadioButton GroupName="numgrp">2</RadioButton> </StackPanel>
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Control
System.Windows.Controls.ContentControl
System.Windows.Controls.Primitives.ButtonBase
System.Windows.Controls.Primitives.ToggleButton
System.Windows.Controls.RadioButton
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.