Skip to content

Latest commit

 

History

History
62 lines (41 loc) · 4.35 KB

File metadata and controls

62 lines (41 loc) · 4.35 KB
-api-id -api-type
T:Microsoft.UI.Xaml.Controls.RadioButton
winrt class

Microsoft.UI.Xaml.Controls.RadioButton

-description

Represents a button that allows a user to select a single option from a group of options.

-xaml-syntax

<RadioButton .../>
-or-
<RadioButton ...>
  content
</RadioButton>
-or-
<RadioButton ...>stringContent</RadioButton>

-remarks

Tip

For more info, design guidance, and code examples, see Radio buttons.

Use RadioButton controls to limit a user's selection to a single choice within a set of related, but mutually exclusive, choices. You group RadioButton controls by putting them inside the same parent container or by setting the GroupName property on each RadioButton to the same value.

Radio button controls

A RadioButton has two states: selected or cleared. When a RadioButton is selected, its IsChecked property is true. When a RadioButton is cleared, its IsChecked property is false. A RadioButton can be cleared by clicking another RadioButton in the same group, but it cannot be cleared by clicking it again. However, a RadioButton can be cleared programmatically by setting its IsChecked property to false.

Control style and template

You can modify the default Style and ControlTemplate to give the control a unique appearance. For information about modifying a control's style and template, see XAML styles. The default style, template, and resources that define the look of the control are included in the generic.xaml file. For design purposes, generic.xaml is installed with the Windows App SDK NuGet package. By default, this location is \Users\<username>\.nuget\packages\microsoft.windowsappsdk\<version>\lib\uap10.0\Microsoft.UI\Themes\generic.xaml. Styles and resources from different versions of the SDK might have different values.

XAML also includes resources that you can use to modify the colors of a control in different visual states without modifying the control template. Modifying these resources is preferred to setting properties such as Background and Foreground. For more info, see the Light-weight styling section of the XAML styles article.

-examples

Tip

For more info, design guidance, and code examples, see Radio button.

[!div class="nextstepaction"] Open the WinUI 3 Gallery app and see the RadioButton in action

The WinUI 3 Gallery app includes interactive examples of most WinUI 3 controls, features, and functionality. Get the app from the Microsoft Store or get the source code on GitHub

The following example shows three radio buttons. The first two radio buttons are grouped together. The remaining radio button is not grouped explicitly, which means that you can select the third radio button and either the first or second. When you select a radio button, a TextBlock displays the name of the group, if the radio button has an explicit group name, and the name of the radio button.

[!code-xaml1]

[!code-csharp11]

-see-also

Radio buttons overview, ToggleButton, CheckBox, ToggleSwitch, Controls list p://msdn.microsoft.com/library/8db4347b-91d6-4659-91f2-80ecf7bbb596)