MessageBox
A MessageBox is a dialog that is used to display information with a specific intent to the user. It uses the
DialogService
to display the dialog.
The DialogService
is a singleton service that can be injected into any component. It exposes methods to show a dialog.
For working with a MessageBox
, the following methods are available:
ShowSuccess
/ShowSuccessAsync
ShowWarning
/ShowWarningAsync
ShowInfo
/ShowInfoAsync
ShowError
/ShowErrorAsync
ShowConfirmation
/ShowConfirmationAsync
ShowMessageBox
/ShowMessageBoxAsync
DialogService
, see the DialogService page.
For defining the information to display in the MessageBox
, the MessageBoxData
class is used. See the API documentation
below for the available properties.
The MessageBoxData
class is then used as the generic type parameter for the DialogParameters
class.
The DialogParameters
class is used to pass parameters to the DialogService
when showing a dialog.
When both the PrimaryButton
and SecondaryButton
properties are set, the MessageBox
will be
displayed as a modal. This means that the user has to click one of the buttons to close the dialog. It cannot be closed by clicking
outside of the dialog. Clicking PrimaryButton
will return true
and clicking SecondaryButton
will
return false
as the dialog result. See the Console log for these return values.
Internally, the ShowMessageBox
methods call the ShowDialog
methods. If is possible to directly call these methods and thereby have
access to all of the parameters. The ShowMessageBox
variants are just convenience methods that make ite easier to work with panels.
Example
MessageBoxAsync
The buttons below call the async MessageBox methods on the DialogService.
Last result:
MessageBoxAsync
Same examples as above , but with custom primary botton texts
Last result:
Documentation
MessageBoxContent Class
Properties
Name | Type | Default | Description |
---|---|---|---|
Icon | Icon? | Gets or sets the name of the icon to display. | |
IconColor | Color | Neutral | Gets or sets the color of the icon to display. |
Intent | MessageBoxIntent | Success | Gets or sets the intent of the message box. See MessageBoxIntent for details. |
MarkupMessage | MarkupString? | Gets or sets the html text to display in the message box. | |
Message | string? | Gets or sets the text to display in the message box. | |
Title | string? | Gets or sets the title of the message box. |
DialogParameters<MessageBoxData> Class
Properties
Name | Type | Default | Description |
---|---|---|---|
Alignment | HorizontalAlignment | Center | Gets or sets the dialog position: left (full height), right (full height) or screen middle (using Width and Height properties). HorizontalAlignment.Stretch is not supported for this property. |
AriaDescribedby | string? | Gets or sets the element that describes the element on which the attribute is set. | |
AriaLabel | string? | Gets or sets the value that labels an interactive element. | |
AriaLabelledby | string? | Gets or sets the element that labels the element it is applied to. | |
Content | TContent | Gets or sets the content to pass to and from the dialog. | |
DialogBodyStyle | string | Gets or sets the extra styles applied to the Body content. | |
DialogType | DialogType | Dialog | Gets or sets the type of dialog. |
DismissTitle | string? | Close | Gets or sets the Title of the dismiss button, display in a tooltip. Defaults to 'Close'. |
Height | string? | Gets or sets the height of the dialog. Must be a valid CSS height value like '600px' or '3em' Only used if Alignment is set to 'HorizontalAlignment.Center' | |
Item | Object | ||
Modal | bool? | True | Determines if the dialog is modal. Defaults to true. Obscures the area around the dialog. |
PreventDismissOnOverlayClick | bool | False | Determines if a modal dialog is dismissible by clicking outside the dialog. Defaults to false. |
PreventScroll | bool | True | Prevents scrolling outside of the dialog while it is shown. |
PrimaryAction | string? | OK | Gets or sets the text to display for the primary action. |
PrimaryActionEnabled | bool | True | When true, primary action's button is enabled. |
SecondaryAction | string? | Cancel | Gets or sets the text to display for the secondary action. |
SecondaryActionEnabled | bool | True | When true, secondary action's button is enabled. |
ShowDismiss | bool | True | Gets or sets a value indicating whether show the dismiss button in the header. Defaults to true. |
ShowTitle | bool | True | Gets or sets a value indicating whether show the title in the header. Defaults to true. |
Title | string? | Gets or sets the title of the dialog. | |
TrapFocus | bool? | True | Gets or sets a value indicating whether if dialog should trap focus. Defaults to true. |
ValidateDialogAsync | Func<Task<bool>> | Function that is called and awaited before the dialog is closed. | |
Visible | bool | True | Gets or sets if a dialog is visible or not (Hidden) |
Width | string? | Gets or sets the width of the dialog. Must be a valid CSS width value like '600px' or '3em' |
EventCallbacks
Name | Type | Description |
---|---|---|
OnDialogClosing | EventCallback<DialogInstance> | Callback function that is called and awaited before the dialog fully closes. |
OnDialogOpened | EventCallback<DialogInstance> | Callback function that is called and awaited after the dialog renders for the first time. |
OnDialogResult | EventCallback<DialogResult> | Callback function for the result. |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
Add | string parameterName Object value | void | |
Get<T> | string parameterName | T? | |
GetDictionary | Dictionary<string, Object> | ||
GetEnumerator | IEnumerator<KeyValuePair<string, Object>> | ||
TryGet<T> | string parameterName | T? |