Using Themes in your WPF-Applications

Tags: wpf

Recently we found a nice project on CodePlex, so called WPF Themes.
We thought we should give it a try and see how easy it is to use WPF Themes in our own application.

The installation process went easy using NuGet and all you need todo to apply one of the available themes to your app is to set it in the XAML or by code.
XAML: Add the following lines to your MainWindow.xaml

xmlns:themes="clr-namespace:WPF.Themes;assembly=WPF.Themes"
themes:ThemeManager.Theme="ExpressionDark"
Background="{DynamicResource WindowBackgroundBrush}"

By Code: Set the Theme using the following Expression:

WPF.Themes.ThemeManager.ApplyTheme(System.Windows.Application.Current, "ExpressionDark");
SetResourceReference(BackgroundProperty, "{DynamicResource WindowBackgroundBrush}");

If you set the Theme using XAML, the Theme is applied at Designtime. Unfortunately, the Visual Studio built-in Designer does not know nothing about the new Theme-dll and so the Preview of the window could not be loaded into the Designer.
You can solve this problem, by copy the WPF.Themes.dll to the right location.
Find out where the WPF.Themes dll has been installed on your System by right-click on the WPF.Themes at the Project-References:

image

Open the Directory and copy the WPF.Themes.dll to the following location:

(64 Bit System) C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
(32 Bit System) C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE

That’s it.
Now you can see the Theme directly in the Visual Studio Designer.
The following snippet gives an overview of the available Themes (May 2012):

foreach(string theme in WPF.Themes.ThemeManager.GetThemes()) {
    Trace.WriteLine(theme);
}
  • ExpressionDark
  • ExpressionLight
  • ShinyBlue
  • ShinyRed
  • DavesGlossyControls
  • WhistlerBlue
  • BureauBlack
  • BureauBlue
  • BubbleCreme
  • TwilightBlue
  • UXMusingsRed
  • UXMusingsGreen
  • UXMusingsBubblyBlue

!Enjoy
-- your X4U Dev-Team

Add a Comment