Create cool dialog or message box with PowerShell and WPF


In this post, I will an easy way to display cool messagebox or dialogs with PowerShell and WPF.

How to get samples ?


What is it ?
The library I will talk about it is called SimpleDialog.
It has been created by Maurício Vielmo Schmaedeck who did a really nice job.
You can find the GitHub repo here.

How it looks like ?
The library is composed of 6 dialogs.
- Information
- Success 
- Warning
- Error
- Critical error
- Progress

Where to find it ?
You can find the library on this GitHub repo.

How to install it ?
1 / Create a folder assembly
2 / Create a folder resources
In this step I guess you already have a ps1 and XAML files. If not you can find them in the download link.
My project will look like as below:
3 / Download the Nuget.exe file. You can find it here.
4 / Copy the nuget.exe in your project folder.
5 / Now we will download the required dll to play with the library
6 / Use the below command to download it.
7 / The DLL file will be available in the folder SimpleDialogs.1.0.3\lib\net45
Note that the version may change.
8 / Copy the SimpleDialogs.dll file to the assembly folder previously created
Now we have everything we need, let us see how to implement it.

How to implement it ?

XAML part
1 / Copy the below lines in the Window part.
2 / See below my Window part after
3 / Add the below Resources part after the Window part.
4 / See below my full XAML file.

PS1 part
1 / Add the below line, at the beginning of your script, to load the assembly
2 / Your dialog will be displayed after clicking on a button.
We will now see how to use it.

How to use it ?
The simpleDialog is composed of 6 dialogs which are divised in two classes AlertDialog and ProgressDialog.

The dialogs below will be used in the class [SimpleDialogs.Controls.AlertDialog]
- Information
- Success 
- Warning
- Error
- Critical error

The Progress dialog will be used using the class [SimpleDialogs.Controls.ProgressDialog]
Use the below part to create and display your Alert Dialog
Use the below part to create and display your Progress Dialog
To choose what kind of dialog to display you have to play with the AlertLevel property.
See below which AlertLevel to use depending of the Dialog
- Information: information
- Success: Success 
- Warning: warning
- Error: error
- Critical error: critical

See below how to use it:
To change title and message of your Dialog use the below properties:
See below how to use it:
By default Dialogs will look like as below:


Customize the Dialog
There are several properties available to customize the main design of the design like colors, buttons...
To customize it, use the below properties (I don't use all of them in this sample)
For instance if you want to change the main color of a Dialog use the property Foreground.
You can also choose what kind of button to display in your Dialog. For instance you can choose to dislay a Yes and No button or also choose to display a Copy to clipbard button. This one will copy text content in the clipboard.
In the below GUI, I added some properties to customize to change the design of my Dialogs.

See below all properties available for the AlertDialog
See below all properties available for the ProgressDialog

Share this

Related Posts

Previous
Next Post »