Quick Start – MahApps Metro

I discovered the excellent MahApps Metro libraries a while back but it wasn’t until I started using github:Windows that I was inspired to really start using this excellent library.

Basically MahApps Metro offers a bunch of styles and controls which duplicate aspects of Windows 8 UI but ofcouse they can be used on non-Windows 8 versions of Windows. For example, I have code on both WinXP and Windows 7 using these libraries and they look great.

This post is just a quick “how to quickly get up and running” with MahApps.

  • Let’s start by creating a WPF Application in Visual Studio.
  • Now using NuGet type MahApps.Metro into the search box of NuGet and install MahApps.Metro
  • In the MainWindow.xaml.cs change the base class from Window to MetroWindow and add using MahApps.Metro.Controls;
  • In the MainWindow.xaml change Window to MetroWindow add the namespace if need be (for example xmlns:Controls=”clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro”)
  • Finally add A Window.Resources section to the MainWindow.xaml file as per the code below to enable the Metro styles
<Window.Resources>
   <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
         <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
         <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
         <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
         <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
         <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
      </ResourceDictionary.MergedDictionaries>
   </ResourceDictionary>
</Window.Resources>

Note: After installing MahApps.Metro using NuGet the page http://mahapps.com/MahApps.Metro/ is displayed, it contains the steps above plus more so obviously read that for a fuller explanation. I’ve written these steps out just to show the bare minimum I need to do to get started.