Part 3: Powershell wpf MahApps.Metro theme step by step

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.

microsoft powershell visual studio package manager console, install-package mahapps.metro controlzex wpf thems packages

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

Microsoft Powershell Mahapps.Metro wpf them graphical user interface gui windows presentation frameworks platform themes

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  to .

#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 and below Title. You can change the Color and base color, I have provided supported color names which you can change anytime.

   
       
           
           
           
            
            
            
            
           
           1
       
   

#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 

Microsoft windows powershell wpf xaml visual studio gui script, metrowindow, Mahapps.Metro theme presentation, xmlns controls, mergedictionaries resourcedicionary xml winfx blend assembly

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.

Powershell mainwindow, xaml wpf theme mahapps.metro cool theme royal windows presentation frameworks, complete script code

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 = @"            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"          xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"          Title="MainWindow" Height="450" Width="800">                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              "@    #Read the form  $Reader = (New-Object System.Xml.XmlNodeReader $xaml)   $Form = [Windows.Markup.XamlReader]::Load($reader)     #AutoFind all controls  $xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]")  | ForEach-Object {     New-Variable  -Name $_.Name -Value $Form.FindName($_.Name) -Force   }    $ComboBox1.ItemsSource =  @('Item1','Item2','Item3')  $combobox1.SelectedItem = 'Item1'  $Image1.Source = 'C:TempMetroDarkThemeImage.png'  #$DataGrid.RowBackground = 'Black'  $Datagrid.ItemsSource = Get-Service | Select-Object Name, Status, StartType -First 5  $ListBox.ItemsSource =  @('Item1','Item2','Item3')  $combobox1.SelectedItem = 'Item1'    #Mandetory last line of every script to load form  [void]$Form.ShowDialog()  

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



via Latest imported feed items on VMware Blogs https://ift.tt/2JcVUUz
RSS Feed

If New feed item from https://blogs.vmware.com/feed, then send me an email at kr

IFTTT

Comments

Popular posts from this blog

Evernote cuts staff as user growth stalls

The best air conditioner

We won't see a 'universal' vape oil cartridge anytime soon