Class Checkbox
A control that lets users make a binary choice between two mutually exclusive options.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class Checkbox : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<CheckboxState>, IValidatableElement<CheckboxState>, INotifyValueChanged<CheckboxState>, IPressable
Remarks
The Checkbox component is a fundamental user interface control that allows users to select or deselect an option. It's particularly useful in forms, settings panels, and anywhere users need to make binary choices.
Checkboxes can exist in three states: checked, unchecked, and intermediate. The intermediate state is useful when representing a collection of sub-items where only some are selected.
The intermediate state cannot be directly toggled by user interaction - it can only be set programmatically. Users can only toggle between checked and unchecked states.
- Users need to select one or more options from a list
- Users need to toggle a single option on or off
- Multiple independent choices need to be presented
Examples
Basic checkbox usage in UXML.
<UXML xmlns:appui="Unity.AppUI.UI">
<appui:Checkbox label="Accept terms and conditions" />
</UXML>
Creating a checkbox group programmatically.
var container = new VisualElement();
var option1 = new Checkbox ;
var option2 = new Checkbox ;
var selectAll = new Checkbox ;
option1.RegisterValueChangedCallback(evt => UpdateSelectAllState());
option2.RegisterValueChangedCallback(evt => UpdateSelectAllState());
selectAll.RegisterValueChangedCallback(evt => {
if (evt.newValue != CheckboxState.Intermediate)
});
container.Add(selectAll);
container.Add(option1);
container.Add(option2);
Creating a validated checkbox.
var checkbox = new Checkbox { label = "Must be checked" };
checkbox.validateValue = (state) => state == CheckboxState.Checked;
checkbox.RegisterValueChangedCallback(evt => {
// invalid will be automatically updated based on validateValue
if (checkbox.invalid)
{
Debug.Log("Please check the box to continue");
}
});
Constructors
Checkbox()
Default constructor.
Declaration
public Checkbox()
Fields
boxUssClassName
The Checkbox box styling class.
Declaration
public const string boxUssClassName = "appui-checkbox__box"
Field Value
| Type | Description |
|---|---|
| string |
checkmarkUssClassName
The Checkbox checkmark styling class.
Declaration
public const string checkmarkUssClassName = "appui-checkbox__checkmark"
Field Value
| Type | Description |
|---|---|
| string |
emphasizedUssClassName
The Checkbox emphasized mode styling class.
Declaration
public const string emphasizedUssClassName = "appui-checkbox--emphasized"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The Checkbox label styling class.
Declaration
public const string labelUssClassName = "appui-checkbox__label"
Field Value
| Type | Description |
|---|---|
| string |
partialCheckmarkUssClassName
The Checkbox partial checkmark styling class.
Declaration
public const string partialCheckmarkUssClassName = "appui-checkbox__partialcheckmark"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The Checkbox size styling class.
Declaration
public const string sizeUssClassName = "appui-checkbox--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The Checkbox main styling class.
Declaration
public const string ussClassName = "appui-checkbox"
Field Value
| Type | Description |
|---|---|
| string |
Properties
clickable
Clickable Manipulator for this Checkbox.
Declaration
[CreateProperty]
public Pressable clickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
emphasized
The Checkbox emphasized mode.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool emphasized { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
invalid
The Checkbox invalid state.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
label
The text displayed in the Checkbox label.
Declaration
[CreateProperty]
[UxmlAttribute]
public string label { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
validateValue
The Checkbox validation function.
Declaration
[CreateProperty]
public Func<CheckboxState, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<CheckboxState, bool> |
value
The Checkbox value.
Declaration
[CreateProperty]
[UxmlAttribute]
public CheckboxState value { get; set; }
Property Value
| Type | Description |
|---|---|
| CheckboxState |
Methods
SetValueWithoutNotify(CheckboxState)
Set the Checkbox value without notifying the change.
Declaration
public void SetValueWithoutNotify(CheckboxState newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| CheckboxState | newValue | The new Checkbox value. |