开发者

WPF Designing application to be dynamically skinnable

开发者 https://www.devze.com 2023-03-30 09:58 出处:网络
I\'m designing a f开发者_运维技巧airly complex WPF application, many modules that are going to be loaded with Prism v4 (some user controls will be in separate dll\'s, as well as some other functions/p

I'm designing a f开发者_运维技巧airly complex WPF application, many modules that are going to be loaded with Prism v4 (some user controls will be in separate dll's, as well as some other functions/plugins). Since I'm just starting the WPF I have a few questions.

I'd like all of the GUI to be "skinnable" in a way that the user can click and choose a different color scheme, and the entire GUI changes the display to the user choice - the main screen, including all of the modules (ie, skin changes at runtime)

Q: Can you recommend some general approach with this? For example, can I just write Xaml without specifying any style (specifically, not bind it to a dynamic style) and it can change in runtime? How can I then switch the active skin so it would affect all of the loaded user controls?

Thanks


basically, all you have to do is swap out resource dictionaries. these should hold your styles and brushes, etc. for the whole application. you can even keep these "skins" in external assemblies.

you should look at ComponentResourceKeys for "naming" the external resources, and here is a bit of code on how to load the resources from said external assembly:

using (FileStream fs = new FileStream("MainResources.xaml", FileMode.Open))
{
    ResourceDictionary dic = (ResourceDictionary) XamlReader.Load(fs);
    Resources.MergedDictionaries.Clear();
    Resources.MergedDictionaries.Add(dic);
}

here is a demo on codeproject

0

精彩评论

暂无评论...
验证码 换一张
取 消