PowerShell and WPF: Customize MahApps Dialog

Reply A+ A-

By default MahApps Dialogs are displayed with default text like OK and Cancel. In this post, I will show you how to change those values and add your own text.

The default behavior
In this below example a simple validation dialog with OK and Cancel button is displayed.
To display this dialog I used the class MessageDialogStyle with method AffirmativeAndNegavtive to display an OK/Cancel dialog.
See below the result (as you can see, buttons are OK and Cancel by default):

Now let's see how to change button values.

MetroDialogSettings: Customize your dialog
To replace OK and Cancel values, you have to use the class MetroDialogSettings:

We will first create the object for this class, as below:
See below available properties for this object:
As you may noticed there are two properties that will be helpful to customize our buttons text:
- AffirmativeButtonText : OK
- NegativeButtonText : Cancel

Now we will change those properties and add our text and apply them to our object Button_Style:
See below the full code:
See below the result:

More custo
Change Dialog theme
You can change the dialog theme using the ColorScheme property that contains three values:

See below the dialog in action depeding of those properties:
Dialog with Accented
Dialog with Inverted
Dialog with Theme

Change dialog title size
See below the default dialog Title size:
You can change it easily using the DialogTitleFontSize property, as below:
See below the new result:

Change dialog message size
See below the default dialog message size:
You can change it easily using the DialogMessageFontSize property, as below:
See below the result:

What's next ?
In the next post I will explain how to diplay differents kinds of dialog using MahApps API.
- Basic Dialog
- Validation Dialog
- Input Dialog
- Login Dialog

WPF_Mahapps 7565651146965811759

Enregistrer un commentaire

Accueil item



Learn KQL in one month

You want to support me ?

Mes articles en français

Books in French