Class MenuRadioGroup
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class MenuRadioGroup : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, INotifyValueChanged<string>
Remarks
This is the UI Toolkit counterpart of the web registry's DropdownMenuRadioGroup /
ContextMenuRadioGroup. It reuses the existing menu machinery rather than introducing a
second kind of row: every MenuItem it contains is turned into a
selectable row with a Radio bullet, and
the group guarantees exactly one of them is selected at a time.
The group's value is the key of the selected row, which mirrors RadioGroup and keeps the selection stable when rows are rebuilt or reordered. A row with no key is left alone.
Unlike a checkbox row, an already-selected radio row cannot be toggled off: clicking it again leaves the selection where it is, so the group is never empty once a value has been set.
Examples
A density picker inside a menu.
<ui:Menu>
<ui:MenuSection title="Density">
<ui:MenuRadioGroup value="normal">
<ui:MenuItem key="compact" label="Compact" />
<ui:MenuItem key="normal" label="Normal" />
<ui:MenuItem key="comfort" label="Comfort" />
</ui:MenuRadioGroup>
</ui:MenuSection>
</ui:Menu>
Reacting to the selection in C#.
var group = new MenuRadioGroup { value = "normal" };
group.Add(new MenuItem { key = "compact", label = "Compact" });
group.Add(new MenuItem { key = "normal", label = "Normal" });
group.Add(new MenuItem { key = "comfort", label = "Comfort" });
group.RegisterValueChangedCallback(evt => SetDensity(evt.newValue));
Constructors
MenuRadioGroup()
Default constructor.
Declaration
public MenuRadioGroup()
Fields
ussClassName
The MenuRadioGroup main styling class.
Declaration
public const string ussClassName = "appui-menuradiogroup"
Field Value
| Type | Description |
|---|---|
| string |
Properties
contentContainer
The MenuRadioGroup content container. Rows are added directly to the group.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
value
The key of the currently selected row.
Declaration
[CreateProperty]
[UxmlAttribute]
public string value { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
GetMenuItems()
The rows of this group.
Declaration
public IEnumerable<MenuItem> GetMenuItems()
Returns
| Type | Description |
|---|---|
| IEnumerable<MenuItem> | The rows, in document order. |
SetValueWithoutNotify(string)
Set the selected key without raising a ChangeEvent_1.
Declaration
public void SetValueWithoutNotify(string newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | newValue | The key of the row to select. |