How to Apply a Default Theme to Your WPF Application |
| This tutorial explains how to select a specific default Windows theme to use with your WPF application. |
| The following are themes that Microsoft has created, and the corresponding theme dictionary URIs: |
- Windows Vista: themes\Aero.NormalColor.xaml
- Windows XP: themes\Luna.NormalColor.xaml
- Olive Green Windows XP: themes\Luna.Homestead.xaml
- Silver Windows XP: themes\Luna.Metallic.xaml
- Windows XP Media Center Edition 2005 and XP Tablet PC Edition 2005: themes\Royale.NormalColor.xaml
- Windows Classic: themes\Classic.xaml
|
Tutorial (using Visual Studio 2005) |
- Right-click the References folder in your Visual Studio WPF project, and choose Add Reference. Under .Net select the PresentationFramework.(Theme).
For example, the Aero theme would be PresentationFramework.Aero
- Open the App.xaml file. This is the file that defines resources for you application.
- Add a ResourceDictionary beneath ResourceDictionary.MergedDictionaries and set its Source property equal to /PresentationFramework.(Theme);component/themes/(theme dictionary URI).
For example, for the Royale theme, my App.xaml file would have the following:
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="XAML_Test.App"
StartupUri="Window1.xaml">
<Application.Resources>
<!-- Resources scoped at the Application level should be defined here. -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Royale;component/themes/royale.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
- That's All Folks... Now just Save and Run your project, and by default, all of your controls should be styled according to the theme that you have applied. Remeber, however, that any style changes you have made to the control itself, to the page, or to the window will override the application theme.
|
| Written by: Jennifer Foster 02/06/2007 |