MxMessageBox
The MxMessageBox
dialog allows you to display messages and ask simple questions to users.
MxMessageBox
supports Eremex paint themes. It is correctly rendered in the light and dark theme variants.
Use the static MxMessageBox.Show
method overloads to display a dialog. The MxMessageBox.Show
methods return the result of the dialog (the button clicked by a user).
Show Method Overloads
Two MxMessageBox.Show
method overloads are available:
public static MessageBoxResult MxMessageBox.Show(Window? owner, string text, string? title = null, MessageBoxButtons buttons = MessageBoxButtons.Ok, MessageBoxIcon icon = MessageBoxIcon.None, MessageBoxResult defaultButton = MessageBoxResult.None, Action<MxMessageBox>? configure = null)
owner — The window that will own the message box. If this parameter is
null
, theMxMessageBox
automatically identifies the owner: the owner is the last active window, or the application's main window.text — The text to display in the dialog.
title — The dialog's title.
buttons — An
Eremex.AvaloniaUI.Controls.MessageBoxButtons
enumeration value that specifies buttons to display in the dialog. Available values include:Ok
,OkCancel
,YesNoCancel
,YesNo
,AbortRetryIgnore
,RetryCancel
icon — One of the predefined icons to display before the text. Set the property to
MessageBoxIcon.None
to hide the icon.defaultButton — Identifies the default button. The default button is the one that is initially focused when the dialog is displayed. When a user presses ENTER, the default button is clicked.
configure — A delegate to perform additional dialog customization (for instance, the dialog's icon in the title bar, or the alignment of buttons).
Example
The following example displays a message box with three buttons - Yes, No and Cancel.
MessageBoxResult result = MxMessageBox.Show(null, "The document has changed."+ Environment.NewLine+ "Do you want to save the changes?", "Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning, MessageBoxResult.Yes); if (result == MessageBoxResult.Yes) { //... }
Another MxMessageBox.Show
method overload contains only one parameter.
public static MessageBoxResult MxMessageBox.Show(Action<MxMessageBox> configure)
configure — A delegate to customize the dialog.
Example
var res = MxMessageBox.Show(configure: msgBox => { msgBox.Text = "Error opening the database"; msgBox.Title = "Error"; msgBox.Buttons = MessageBoxButtons.Ok; msgBox.ButtonAlignment = Avalonia.Layout.HorizontalAlignment.Center; msgBox.Window.Icon = new WindowIcon(AssetLoader.Open(new Uri("avares://DemoCenter/Assets/EMXControls.ico"))); });