-
Notifications
You must be signed in to change notification settings - Fork 0
04.Message Boxes
You can show message boxes using static functions of DialogHelper
class:
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.
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:
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;
A string message to be displayed.
A string text to be displayed as title for the message.
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 | ![]() |
OK | Blue |
Warning | ![]() |
OK | Yellow |
Error | ![]() |
OK | Red |
Question | ![]() |
Yes, No | Green |
You can set the theme color for each type using static properties: DialogParameters.MessageInfoColor
, DialogParameters.MessageWarningColor
, DialogParameters.MessageErrorColor
, DialogParameters.MessageQuestionColor
.
an UIElement
that will be displayed as icon in a ViewBox
control.
a DialogButtons
enum that has one of the following values:
public enum DialogButtons
{
None,
Ok,
OkCancel,
YesNo,
YesNoCancel
}
A Brush
that will be used as theme for the message box. It will be set as background brush for the dialog.