RadioButton
Introduction
RadioButtons provide a way to display multiple mutually-exclusive options to the user. Clicking on one RadioButton unchecks all other RadioButtons in a group.
Code Example: Creating RadioButtons
The following code creates RadioButtons for selecting difficulty:
// Initialize
var stackPanel = new StackPanel();
stackPanel.AddToRoot();
var easyRadioButton = new RadioButton();
stackPanel.AddChild(easyRadioButton);
easyRadioButton.Text = "Easy";
var mediumRadioButton = new RadioButton();
stackPanel.AddChild(mediumRadioButton);
mediumRadioButton.Text = "Medium";
var hardRadioButton = new RadioButton();
stackPanel.AddChild(hardRadioButton);
hardRadioButton.Text = "Hard";
Grouping by Container
RadioButtons automatically group themselves based on their container. If RadioButtons are added directly to a Screen or Component, then they all use the same group and will all be mutually exclusive.
Alternatively, RadioButton instances can be grouped into separate containers (such as StackPanels) to control their grouping. the following example shows two StackPanels, each with three RadioButton instances.

At runtime, the RadioButtons in each StackPanel are mutually exclusive.

The following code creates two independent RadioButton groups side by side, one for difficulty and one for game mode. Selecting a RadioButton in one group does not affect the other group.
Checked and Unchecked Events
RadioButton inherits Checked and Unchecked events from ToggleButton. Checked fires when a RadioButton becomes selected; Unchecked fires when it is deselected because another RadioButton in the same group was chosen.
Reading IsChecked
To determine which RadioButton is selected at any point, check the IsChecked property on each instance. IsChecked is true for the selected button and false for all others in the group.
Label Wrapping
Label wrapping behavior can be controlled by modifying the visual width and the internal label width values. The following code shows how to create two RadioButtons - one wraps its text and one has the text extend to the right.
Last updated
Was this helpful?

