Class RadioGroup
A container component that manages a set of radio buttons, allowing users to select one option from multiple choices.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class RadioGroup : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<string>, IValidatableElement<string>, INotifyValueChanged<string>
Remarks
RadioGroup is a form control that manages a group of Radio buttons, ensuring that only one option can be selected at a time. It's commonly used in forms and settings interfaces where users need to choose exactly one option from a set of mutually exclusive choices.
The RadioGroup automatically handles the mutual exclusivity of its Radio children - when one radio button is selected, all others in the group are automatically deselected.
Note: Each Radio element within the group must have a unique 'key' property to function properly.
Examples
Basic RadioGroup with multiple options — Creating a simple radio group with three options.
<UXML>
<RadioGroup>
<Radio key="option1" label="Option 1" />
<Radio key="option2" label="Option 2" />
<Radio key="option3" label="Option 3" />
</RadioGroup>
RadioGroup with validation and event handling — Creating a radio group programmatically with validation and change event handling.
var radioGroup = new RadioGroup();
// Add radio buttons
var radio1 = new Radio { key = "small", label = "Small" };
var radio2 = new Radio { key = "medium", label = "Medium" };
var radio3 = new Radio { key = "large", label = "Large" };
radioGroup.Add(radio1);
radioGroup.Add(radio2);
radioGroup.Add(radio3);
// Add validation
radioGroup.validateValue = (value) => value != "large";
// Listen for changes
radioGroup.RegisterValueChangedCallback(evt => {
Debug.Log($"Selected size: ");
});
RadioGroup with default selection and styling — Creating a radio group with a pre-selected option and styled radio buttons.
<UXML>
<RadioGroup value="option2">
<Radio key="option1" label="Standard" size="M" />
<Radio key="option2" label="Premium" size="M" emphasized="true" />
<Radio key="option3" label="Enterprise" size="M" />
</RadioGroup>
Constructors
RadioGroup()
Default constructor.
Declaration
public RadioGroup()
Fields
ussClassName
The RadioGroup main styling class.
Declaration
public const string ussClassName = "appui-radiogroup"
Field Value
| Type | Description |
|---|---|
| string |
Properties
contentContainer
The RadioGroup content container.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
invalid
The RadioGroup invalid state.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
validateValue
The RadioGroup validation function.
Declaration
[CreateProperty]
public Func<string, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<string, bool> |
value
The selected item key.
Declaration
[CreateProperty]
[UxmlAttribute]
public string value { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | if the value is out of range. |
Methods
SetValueWithoutNotify(string)
Set the value without notifying the listeners.
Declaration
public void SetValueWithoutNotify(string newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | newValue | The new value. |