Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I match my controls' styles to the current theme? (WPF)

Tags:

styles

wpf

themes

If I create a custom control with WPF, how can I provide styles for the control that match the currently applied theme (Aero, Luna, Classic, etc.)?

For example I'd like to apply the following when using Aero:

<Style>
    <Setter Property="Background" Value="White"/>
</Style>

But then apply a different style when using Luna:

<Style>
    <Setter Property="Background" Value="#DFDFDF"/>
</Style>

Can I somehow extend the base themes to provide support for my new control?

like image 421
ajlane Avatar asked Feb 12 '09 14:02

ajlane


1 Answers

Some links that might be prove helpful:

http://arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific-Windows-theme.aspx

http://www.browsoft.com/tutorials/DefaultTheme.html

http://blogs.msdn.com/wpfsdk/archive/2007/07/31/using-themes-with-custom-controls.aspx

Basically you create resource dictionaries for your custom controls named like this:

Classic.xaml (“Classic” Windows 9x/2000 look on Windows XP.)
Luna.NormalColor.xaml (Default blue theme on Windows XP.)
Luna.Homestead.xaml (Olive theme on Windows XP.)
Luna.Metallic.xaml (Silver theme on Windows XP.)
Royale.NormalColor.xaml (Default theme on the Windows XP Media Center Edition operating system.)
Aero.NormalColor.xaml (Default theme on the Windows Vista operating system.)

Put the different styles for your controls in those files and they will be loaded based on the current theme of the OS.

like image 106
Jason Miesionczek Avatar answered Dec 08 '22 00:12

Jason Miesionczek