Skip to content

04.Message Boxes

eiadxp edited this page May 12, 2018 · 2 revisions

You can show message boxes using static functions of DialogHelper class:

1. DialogHelper.ShowMessage():

These functons return DialogMessage class which is a sub class of DialogBase. It does not block your thread and returns back immediately after showing the dialog, and will not wait for closing. This is useful if you do not need the result of the dialog.

2. DialogHelper.ShowMessageAsync():

Async version of the previous function, which returns the dialog result after closing the dialog. Use it with await keyword inside async method.

All these methods has semilar parameters in verious overloads:

parent :

A Content control that will display the message box. If you used an overload that does not has a parent parameter, or if you used null value for it, the main window of the application will be used as parent, we get this window using:

    parent  = Application.Current?.MainWindow;

text:

A string message to be displayed.

caption:

A string text to be displayed as title for the message.

type:

a DialogMessageType enum that specify the dialog look. It has the following definition:

    public enum DialogMessageType
    {
        Info,
        Question,
        Warning,
        Error
    }

When you use an overload that has this parameter, you will set the icon, buttons, and theme of the message box automatically as in the following table:

type value icon buttons theme
Info Info OK Blue
Warning Info OK Yellow
Error Info OK Red
Question Info Yes, No Green

You can set the theme color for each type using static properties: DialogParameters.MessageInfoColor, DialogParameters.MessageWarningColor, DialogParameters.MessageErrorColor, DialogParameters.MessageQuestionColor.

icon:

an UIElement that will be displayed as icon in a ViewBox control.

buttons:

a DialogButtons enum that has one of the following values:

    public enum DialogButtons
    {
        None,
        Ok,
        OkCancel,
        YesNo,
        YesNoCancel
    }

theme:

A Brush that will be used as theme for the message box. It will be set as background brush for the dialog.