We can swap out the theme before opening any windows in App. That way the app loads up with the correct theme. You can also run this code when the user updates the theme. The only thing you want to put into the theme dictionaries are Brush resources and maybe Colors if you need them. Dark and Light should have whatever looks good to you.
For High Contrast, we should pick from the official SystemColors. If you choose from SystemColors, it will work for any High Contrast variant the user chooses, even if they customize it. Button, for example is one of them. The only way to re-skin them is to make a copy of their ControlTemplate and insert references to our own themed colors. I ripped out the FocusVisualStyle override since the default one seems to work fine for all themes. Simple to implement and simple to understand.
The idea is for each Skin to have a single Resource dictionary. So if you want the Blue Skin to be contained of BlueColors. Like this:. If BlueStyles. It will work however if BlueColors. More about this problem here. Another thing we might want to have is Shared resources, for all skins.
These might depend on Theme resources and should be updated on Skin change. What we can do, is copy the content of some Skin and the content of Shared. This should get the designer working. All of them rely on the Skin to be compiled.
Meaning the XAML file is included in the solution. Out of all the approaches shown, I prefer and recommend the SkinResourceDictionary. It seems the cleanest one and also the only one with the Designer working out of the box. So we can parse and create a ResourceDictionary instance from any file on the hard drive, like this:. This is pretty reasonable since WPF tries to look for the merged resource dictionary in the Assembly.
A possible solution will be to manually parse the XAML file, find all the resource dictionaries and use XamlReader to load them. Or we can just avoid using MergedDictionaries and place all our resources in a single file. As an example, I created this GreenSkin. Usually, this will be just the beginning and you will need to hand tailor the code much more for the specific needs of your App. Want to become an expert problem solver? Check out a chapter from my book Practical Debugging for. NET Developers.
One addition to Lars' answer and DanM's update: When deploying, you must add the aero Dll to the installation dir. I do not think PresentationFramework. According to msdn. NET framework. Apply it in your code and it should work nicely I hope my answer helps you.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.
Remove From My Forums. Asked by:. Archived Forums. Sign in to vote. Does anybody faced this issue or have any solution? Thanks Shreeraj. Thursday, August 23, AM. Friday, August 24, AM.
0コメント