I would like to make my WPF application draw from the currently selected system theme.
To illustrate, here is a Windows Forms version of what I hope to accomplish.
This Windows Form window has a basic menustrip and a toolstrip with to specific theming. Its appearance will change if the user opts to change the theme:
Additionally, it will switch to areo theme when run in Windows 7. I would like to do the same in WPF. But I am unsure about how to make a WPF window styled after the current windows theme. This window (xaml), also has a menustrip and toolstrip control, but does not fully follow the selected Windows theme.
The menu and toolbar controls do not retain the gradient found in the XP Luna themes. Note that unlike other WPF theming posts, I am not trying to override the User Selected Windows theme. This question seems close to mine, but I want to theme all controls to match the selected system theme unless overridden. Does this need to be done on a per control basis? Can this be configured for the entire project? This MSDN article only covers custom controls.
I would appreciate specific examples about how to get the WPF Menu and WPF toolbar controls to match the current system theme.
Edit: It would also be great to know what color to set the menu to such that a system themed stripe appears next to the menu item: (to the left of "Exit")
(to the left of "Exit")
One way is to use system colors like these. They will change based on the theme accordingly. I'm not sure if there's an easier way, but this is a good one =). There's a list below that shows you the colors per theme.
The problem is that WPF controls are internally very different from Windows Forms one's or any other GDI elements. WPF control's look is defined with the help of a different classes in .Net. The same themeing can't just magically be applied to them.
Therefore I would say - yes, you should implement themeing on a per-control basis using the resource files in this question's answer.
I assume we are lucky MS has provided us with those at all. Another thing is that the very existence of those xaml styles proves how much more configurable the WPF framework is.
The theme xaml files are in {Program Files}\Microsoft Expression\Blend 4\SystemThemes\Wpf\
The question that you have initially referenced has an example of how to link a them in it's answer: Windows 7 theme for WPF?
To swap the theme you can dynamically add/remove entry from Application.Current.Resources.MergedDictionaries
You will have to detect the current theme yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With