Part 1: Basic Powershell Wpf Themes Guide step by step
Part 2: Powershell WPF Themes guide step by step
Part 3: Powershell wpf MahApps.Metro theme step by step
As shown in my previous articles using sample xaml as style and themes, here I am using community popular MahApps.Metro wpf theme, This is a royal theme and looks very very cool. Implementation is bit different from the previous step by step guides, but idea is same. To download this theme package, On the Visual studio go to Tools, then NuGet Package Manager and select Package Manager Console. On the command line type Install-Package MahApps.Metro hit enter. It starts downloading two main packages ControlzEx and MahApp.Metro to the underlined folder. These folder contains different version .net dll libraries program files.
I have collected and copied 3 dll files from .net40 folders under lib folders from respective packages. All three dll files are pasted under themes.
- ControlzEx.dll
- System.Windows.Interactivity.dll
- MahApps.Metro.dll
Go through my earlier post for step by step detail on writing complete GUI script - Part 1: Create WPF XAML powershell GUI form with Visual studio, I have created one fresh xaml form and made changes as below.
#1
My Ps1 file with code is kept under MahApps.Metro folder. and Content is as below. This code loads all the .dll assembly libraries from themes folder.
$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
$AssemblyLocation = Join-Path -Path $ScriptPath -ChildPath .\themes
foreach ($Assembly in (Dir $AssemblyLocation -Filter *.dll)) {
[System.Reflection.Assembly]::LoadFrom($Assembly.fullName) | out-null
}
#2
Change starting node syntax from
#3
Next add new namespace xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro".
#4
Below are the dll libraries xaml theme style files, they are embedded in the dll applications. Paste it as it is above
#5
This is last change to the xaml file, change the closing syntax of last line, with below line, and my complete script looks like below screenshot.
to .
Part 3: Create shorter Microsoft Powershell WPF automated clean script
Once these changes are done, I must admit, it looks very beautiful and professional than my earlier themes. I don't have to make a single change to adjust the colors or style unlike previous. There are few more custom controls given, also few nice icons and other stuff available which can be found on official https://mahapps.com/ website., It has detailed documentation.
Download this script from here, It is also available on github.com.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
#Load required libraries #vcloud-lab.com Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase, System.Windows.Forms, System.Drawing $ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path $AssemblyLocation = Join-Path -Path $ScriptPath -ChildPath .\themes foreach ($Assembly in (Dir $AssemblyLocation -Filter *.dll)) { [System.Reflection.Assembly]::LoadFrom($Assembly.fullName) | out-null } [xml]$xaml = @" |
Useful Articles
COOL POWERSHELL FREE ONLINE GUI GENERATOR TOOL, POSHGUI
Generate random password GUI using powershell
Part 1: Create WPF XAML powershell GUI form with Visual studio
Part 2: Powershell and WPF: Build GUI applications tutorial
Part 3: Create shorter Microsoft Powershell WPF automated clean script
Powershell WPF Themes guide step by step
Part 2: Powershell WPF Themes guide step by step
Powershell WPF custom Image based ProgressBar
This post first appeared on Tales From Real IT System Administrators World And Non-production Environment, please read the originial post: here