Easily apply Mahapps on your PowerShell GUI

In a previous post I have shown you how to add the great Mahapps theme to your PowerShell GUI.
Why not going further ? Why not automate this process ?
In this post I'll show you a little tool I have created to update your PowerShell GUI to add Mahapps.

Prerequisites
- At least Powershell v3
- At least .Net Framework 4
- Your GUI should contain an XAML and a PS1 file

You can find here how to create a GUI using an XAML. 
You can also find some great GUI how to on the FoxDeploy site or Dev4Sys.

Now let's see how this tool works.

How to get the tool ?


How it works ?
This tool is very easy to use. 
First use the Browse button to select your project folder. 
This folder must contain your XAML and PS1 files.

Once you have selected your project folder, your files will be automatically saved in a folder Backup_<YourProjetFolderName>  located in your %temp% folder.

Then select the XAML and PS1 files to update using respectively the Select XAML ListBox and Select PS1 ListBox.
Select XAML and Select PS1 ListBox
The GUI Style part allows you to display a testing GUI.
Use the Select a theme ListBox to choose a theme to apply. 
Two themes are available, BaseLight and BaseDark.
Select a theme ListBox
Then use the Select an accent ListBox to choose color to apply to your controls.
Select an accent ListBox
Once you have chosen your theme and your accent, click on the Apply this style to display the testing GUI and see the result.
The testing GUI below uses the BaseLight theme and red accent.
Testing GUI with BaseLight theme and Red accent
Another example using the BaseDark theme and cyan accent.
Testing GUI with BaseDark theme and Cyan accent
Now that we have seen the GUI style part, let's see how to update your existing project.

Use the Update my XAML button, to add Mahapps to your XAML file.
This update is composed of three parts.

1 / It'll first replace <Window with  <Controls:MetroWindow and </Window> with </Controls:MetroWindow> 

2 / Then it'll check if the Mahapps part below is already integrated in your XAML. If not this part will be added.

3 / Finally the below part will be added in your XAML using the theme and accent you have selected.
Use the Update my PS1 button, to add Mahapps to your PS1 file.
As above it will check if Mahapps is already integrated. It'll also check is the presentationframework assembly exists. If not the part below will be added.
When you have updated your PS1 and XAML files the button Test my GUI, will allow you to run your GUI. 

Note: Once Mahapps is integrated in your GUI, some layout problem may occur, but you can resolve them easily by reducing or increasing your controls size.

A log file is available in your project folder to catch your choices and actions.
A little example
Now we that have seen how work the tool, let's apply it on a little GUI and see the final result.
See below the GUI on which we'll apply Mahapps using the tool.
XAML without Mahapps - Before the upgrrade
This tool is composed of two files, an XAML a PS1.
We'll apply it a theme BaseLight and a Red accent, see below:
XAML with Mahapps
As mentioned above, some layout issues may occur. As you can see in the previous GUI, the Options GroupBox size is not adapted. So we just have to increase the Width and it'll be nice. See below the final result.
XAML with Mahapps
Now let's us apply a Cyan accent, as below:
XAML with Mahapps



Hoping this tool could be helpful to you, feel free to contact me by comment or at damien.vanrobaeys@gmail.com for any suggestions, questions ...

Share this

Related Posts

Previous
Next Post »