Class AlertDialog
A dialog that interrupts the user's workflow to communicate an important message and acquire a response.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class AlertDialog : BaseDialog, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, ISizeableElement, IDismissInvocator
Remarks
Alert dialogs interrupt users with urgent information, details, or actions. They are displayed on top of the current window using a Modal component and require user interaction to be dismissed.
Alert dialogs are used for:
- Interrupting workflows with critical information or requiring decisions
- Getting user confirmation before destructive actions
- Displaying important error, warning or success messages
The AlertDialog component supports different semantic variants to convey the nature of the dialog: Default, Confirmation, Information, Destructive, Error, and Warning.
AlertDialogs can have up to three actions:
- Primary action (Required): The main action that confirms or accepts
- Secondary action (Optional): An alternative action
- Cancel action (Optional): Allows users to dismiss the dialog
Use a Modal to display an AlertDialog object.
Examples
Creating a warning dialog for unsaved changes with multiple actions
var alertDialog = new AlertDialog();
alertDialog.variant = AlertSemantic.Warning;
alertDialog.title = "Unsaved Changes";
alertDialog.description = "You have unsaved changes. Do you want to save them before leaving?";
alertDialog.SetPrimaryAction(1, "Save", () => SaveChanges());
alertDialog.SetSecondaryAction(2, "Don't Save", () => DiscardChanges());
alertDialog.SetCancelAction(3, "Cancel");
// Show the alert dialog using a modal
Modal.Build(parentElement, alertDialog)
.SetKeyboardDismiss(true)
.SetOutsideClickDismiss(false)
.Show();
Defining an alert dialog in UXML
<UXML>
<ui:AlertDialog
variant="Information"
title="Update Available"
description="A new version is available. Would you like to update now?"
is-primary-action-disabled="false"
is-secondary-action-disabled="false" />
</UXML>
Showing a simple success confirmation dialog
var confirmationDialog = new AlertDialog();
confirmationDialog.variant = AlertSemantic.Confirmation;
confirmationDialog.title = "Success";
confirmationDialog.description = "Your changes have been saved successfully.";
confirmationDialog.SetPrimaryAction(1, "OK", null);
Modal.Build(parentElement, confirmationDialog)
.SetKeyboardDismiss(true)
.Show();
Constructors
AlertDialog()
Default constructor.
Declaration
public AlertDialog()
Fields
cancelActionUssClassName
The AlertDialog cancel action styling class.
Declaration
public const string cancelActionUssClassName = "appui-dialog__cancel-action"
Field Value
| Type | Description |
|---|---|
| string |
iconUssClassName
The AlertDialog icon styling class.
Declaration
public const string iconUssClassName = "appui-dialog__icon"
Field Value
| Type | Description |
|---|---|
| string |
primaryActionUssClassName
The AlertDialog primary action styling class.
Declaration
public const string primaryActionUssClassName = "appui-dialog__primary-action"
Field Value
| Type | Description |
|---|---|
| string |
secondaryActionUssClassName
The AlertDialog secondary action styling class.
Declaration
public const string secondaryActionUssClassName = "appui-dialog__secondary-action"
Field Value
| Type | Description |
|---|---|
| string |
Properties
cancelButton
The AlertDialog cancel action button.
Declaration
public Button cancelButton { get; }
Property Value
| Type | Description |
|---|---|
| Button |
isPrimaryActionDisabled
Is the primary action button disabled.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool isPrimaryActionDisabled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
isSecondaryActionDisabled
Is the secondary action button disabled.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool isSecondaryActionDisabled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
primaryButton
The AlertDialog primary action button.
Declaration
public Button primaryButton { get; }
Property Value
| Type | Description |
|---|---|
| Button |
secondaryButton
The AlertDialog secondary action button.
Declaration
public Button secondaryButton { get; }
Property Value
| Type | Description |
|---|---|
| Button |
variant
The current variant used by the AlertDialog.
Declaration
[Tooltip("The current semantic variant used by the AlertDialog.")]
[CreateProperty]
[UxmlAttribute]
[Header("Alert Dialog")]
public AlertSemantic variant { get; set; }
Property Value
| Type | Description |
|---|---|
| AlertSemantic |
Methods
SetCancelAction(int, string)
Bind an Action as the cancel action of the Alert.
Declaration
public void SetCancelAction(int actionId, string displayText)
Parameters
| Type | Name | Description |
|---|---|---|
| int | actionId | The Action Identifier. |
| string | displayText | The text to display inside the action's button. |
SetPrimaryAction(int, string, Action)
Bind an Action as the primary action of the Alert.
Declaration
public void SetPrimaryAction(int actionId, string displayText, Action callback)
Parameters
| Type | Name | Description |
|---|---|---|
| int | actionId | The Action Identifier. |
| string | displayText | The text to display inside the action's button. |
| Action | callback | The callback invoked if the action is triggered. |
SetSecondaryAction(int, string, Action)
Bind an Action as the secondary action of the Alert.
Declaration
public void SetSecondaryAction(int actionId, string displayText, Action callback)
Parameters
| Type | Name | Description |
|---|---|---|
| int | actionId | The Action Identifier. |
| string | displayText | The text to display inside the action's button. |
| Action | callback | The callback invoked if the action is triggered. |
Events
dismissRequested
An event invoked when the user requests to dismiss the AlertDialog.
Declaration
public event Action<DismissType> dismissRequested
Event Type
| Type | Description |
|---|---|
| Action<DismissType> |