Original: Get your WPF program to present WIN8 style themes under Win7
Today, using a WPF program I wrote earlier in Win8, I found that the WIN8 effect is now supported (remember that the previous version of. NET 4.0 is not supported). Because WPF controls are self-drawn and are not controlled by system themes, that is, Win8 theme style files are included with. NET 4.5, which is arguably the style that can be used under Win7. Study the discovery, the default theme is stored in the following several DLL files,
When the program starts, the corresponding theme is loaded by default based on the version of the system. For example, Win8 loads the aerolite.dll,win7 and loads the Aero.dll. Use Ilspy to see its specific path
I extracted several of the supported topic paths under. Net 4.5, as follows:
- Win8 (aerolite): /presentationframework.aerolite, version=4.0.0.0, Culture=neutral, publickeytoken= 31bf3856ad364e35;component/themes/aerolite.normalcolor.xaml
- Win7 (Aero): /presentationframework.aero, version=4.0.0.0, Culture=neutral, publickeytoken= 31bf3856ad364e35;component/themes/aero.normalcolor.xaml
- WinXP Bright Blue (Royale): /presentationframework.royale, version=4.0.0.0, Culture=neutral, PublicKeyToken =31bf3856ad364e35;component/themes/royale.normalcolor.xaml
- winxp Blue (Luna): /presentationframework.luna, version=4.0.0.0, Culture=neutral, publickeytoken= 31bf3856ad364e35;component/themes/luna.normalcolor.xaml
- winxp Silver (Luna): /presentationframework.luna, version=4.0.0.0, Culture=neutral, publickeytoken= 31bf3856ad364e35;component/themes/luna.metallic.xaml
- winxp Olive (Luna): /presentationframework.luna, version=4.0.0.0, Culture=neutral, publickeytoken= 31bf3856ad364e35;component/themes/luna.homestead.xaml
- Win98 (Classic): /presentationframework. Classic, version=4.0.0.0, Culture=neutral, Publickeytoken=31bf3856ad364e35;component/themes/classic.xaml
Note: I'm taking the style file path for. Net 4.5, others. NET version of the path may be slightly different, the specific self-ilspy to look at a bit basically out.
With these style paths, you can render Win8 aerolite effects in Win7 as long as you apply a global style at startup:
protected Override void Onstartup (StartupEventArgs e) { varnew Uri ("/presentationframework.aerolite, version=4.0.0.0, culture= Neutral, Publickeytoken=31bf3856ad364e35;component/themes/aerolite.normalcolor.xaml", urikind.relative); = uri; Base . Onstartup (e); }
The effect is as follows, looking at a little fresh feeling.
We can also achieve the retro win XP effect in the same way:
Or the more Retro win 98 effect:
Based on the same principle, we can also just set a control style:
The code is as follows:
Private voidButton_Click (Objectsender, RoutedEventArgs e) { varURI =NewUri ("/presentationframework.aerolite, version=4.0.0.0, Culture=neutral, publickeytoken=31bf3856ad364e35;component/ Themes/aerolite.normalcolor.xaml", urikind.relative); varResourceDictionary = Application.loadcomponent (URI) asResourceDictionary; (Sender asFrameworkElement). RESOURCES.MERGEDDICTIONARIES.ADD (resourceDictionary); }
A final point of knowledge to be introduced is: If we have custom controls, how do we present different styles to different systems like system controls? You can do this by adding a corresponding style resource under the theme folder.
Specifically, see this article: Add Windows 8 Aero Theme support to your WPF Custom Control
Get your WPF program to present WIN8 style themes under Win7