WPF 将应用程序设计为可动态换肤
我正在设计一个相当复杂的 WPF 应用程序,许多模块将使用 Prism v4 加载(一些用户控件将位于单独的 dll 中,以及一些其他功能/插件)。由于我刚刚开始使用 WPF,所以我有几个问题。
我希望所有的 GUI 都是“可换肤”的,用户可以单击并选择不同的配色方案,并且整个 GUI 将显示更改为用户选择 - 主屏幕,包括所有模块(即,皮肤在运行时发生变化)
问:您能推荐一些通用的方法吗?例如,我可以只编写 Xaml 而不指定任何样式(具体来说,不将其绑定到动态样式)并且它可以在运行时更改吗?然后我如何切换活动皮肤,以便它影响所有加载的用户控件?
谢谢
I'm designing a fairly 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您所要做的就是交换资源字典。这些应该在整个应用程序中保存您的样式和画笔等。您甚至可以将这些“皮肤”保留在外部组件中。
您应该查看 ComponentResourceKeys 来“命名”外部资源,
这里有一些关于如何从所述外部程序集加载资源的代码:
这里是代码项目上的演示
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:
here is a demo on codeproject