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
For more information on how to use the 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

Example

The buttons below call the async MessageBox methods on the DialogService.

Success Warning Error Information Confirmation Long message Custom message

Last result:

Download: 

MessageBoxAsync

Example

Same examples as above , but with custom primary botton texts

Success Warning Error Information Confirmation Long message Custom message

Last result:

Download: 

Documentation

MessageBoxContent Class

Properties

Name
Type
Default
Description
IconIcon?
Gets or sets the name of the icon to display.
IconColorColor
Neutral
Gets or sets the color of the icon to display.
IntentMessageBoxIntent
Success
Gets or sets the intent of the message box. See MessageBoxIntent for details.
MarkupMessageMarkupString?
Gets or sets the html text to display in the message box.
Messagestring?
Gets or sets the text to display in the message box.
Titlestring?
Gets or sets the title of the message box.

DialogParameters<MessageBoxData> Class

Properties

Name
Type
Default
Description
AlignmentHorizontalAlignment
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.
AriaDescribedbystring?
Gets or sets the element that describes the element on which the attribute is set.
AriaLabelstring?
Gets or sets the value that labels an interactive element.
AriaLabelledbystring?
Gets or sets the element that labels the element it is applied to.
ContentTContent
Gets or sets the content to pass to and from the dialog.
DialogBodyStylestring
Gets or sets the extra styles applied to the Body content.
DialogTypeDialogType
Dialog
Gets or sets the type of dialog.
DismissTitlestring?
Close
Gets or sets the Title of the dismiss button, display in a tooltip.
Defaults to 'Close'.
Heightstring?
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'
ItemObject
Modalbool?
True
Determines if the dialog is modal. Defaults to true.
Obscures the area around the dialog.
PreventDismissOnOverlayClickbool
False
Determines if a modal dialog is dismissible by clicking
outside the dialog. Defaults to false.
PreventScrollbool
True
Prevents scrolling outside of the dialog while it is shown.
PrimaryActionstring?
OK
Gets or sets the text to display for the primary action.
PrimaryActionEnabledbool
True
When true, primary action's button is enabled.
SecondaryActionstring?
Cancel
Gets or sets the text to display for the secondary action.
SecondaryActionEnabledbool
True
When true, secondary action's button is enabled.
ShowDismissbool
True
Gets or sets a value indicating whether show the dismiss button in the header.
Defaults to true.
ShowTitlebool
True
Gets or sets a value indicating whether show the title in the header.
Defaults to true.
Titlestring?
Gets or sets the title of the dialog.
TrapFocusbool?
True
Gets or sets a value indicating whether if dialog should trap focus.
Defaults to true.
ValidateDialogAsyncFunc<Task<bool>>
Function that is called and awaited before the dialog is closed.
Visiblebool
True
Gets or sets if a dialog is visible or not (Hidden)
Widthstring?
Gets or sets the width of the dialog. Must be a valid CSS width value like '600px' or '3em'

EventCallbacks

Name
Type
Description
OnDialogClosingEventCallback<DialogInstance>
Callback function that is called and awaited before the dialog fully closes.
OnDialogOpenedEventCallback<DialogInstance>
Callback function that is called and awaited after the dialog renders for the first time.
OnDialogResultEventCallback<DialogResult>
Callback function for the result.

Methods

Name
Parameters
Type
Description
Addstring parameterName
Object value
void
Get<T>string parameterName
T?
GetDictionaryDictionary<string, Object>
GetEnumeratorIEnumerator<KeyValuePair<string, Object>>
TryGet<T>string parameterName
T?
Neutral
Accent
Warning
Info
Error
Success
Fill
FillInverse
Lightweight
Disabled
Custom
Success
Warning
Error
Info
Confirmation
Custom
Left
Start
Center
Right
End
Stretch
SpaceBetween
Dialog
MessageBox
Panel
SplashScreen
An error has occurred. This application may no longer respond until reloaded. Reload 🗙