如何在运行时在WPF应用程序中更改外观? [英] How to change skins in wpf application in runtime?

查看:83
本文介绍了如何在运行时在WPF应用程序中更改外观?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我正在开发WPF应用程序,为此我想创建一个选项,该选项允许非程序员更改应用程序的外观(又称皮肤).正如我在WPF文档中看到的那样,窗口和UI控件的外观是用XAML语言定义的,并且可以使用适用于设计人员和其他非程序员的Microsoft Expression Blend程序进行编辑.所以我的问题是:如何使基于WPF的应用程序读取一些XAML代码,并在运行时 创建一些由其描述的窗口和/或UI控件?"

我选择基于WPF和XAML的解决方案,因为据我所知,XAML定义的外观是最可编辑的,并且我已经拥有用于编辑它的工具(混合),但是如果您有更好的主意,请不要犹豫与他人分享我.

您不需要给我确切的代码解决方案.指向适当文档的指针就足够了.

在此先谢谢您.

Dear all,

I''m working on WPF application, for which I''d like to create option which allows non-programmers to change the application''s appearance (aka skin). As I could see in WPF documentation, appearance of windows and UI controls is defined in XAML language, and can be edited using Microsoft Expression Blend program which is suited for designers and other non-programmers. So my question is: "How do I make my WPF based application to read some XAML code and create some window(s) and/or UI controls described by it in runtime?"

I chose WPF and XAML based solution because XAML defined appearance is, to the best of my knowledge, the most editable and I already have tool for editing it (Blend), but if you have better idea, please do not hesitate to share it with me.

You don''t need to give me the exact code solution. A pointer to appropriate documentation will suffice.

Thanks in advance.

推荐答案

您可以将外部xaml文件作为包含样式的ResourceDictionary加载.然后,当您创建窗口,按钮等时,可以使用应用程序中包含的默认样式中的那些样式.当某人想要更改为新皮肤并拥有自己的文件时,可以清除ResourceDictionary,然后加载新文件并将其合并到应用程序类中内置的字典中.

让我知道您是否需要代码示例,因为我是在一些应用程序中执行的.
You can load in an external xaml file as a ResourceDictionary that contains your styles. Then when you create windows, buttons, etc, you can use those styles from the default set that you include in the app. When someone wants to change to a new skin and has their own file, then you can clear your ResourceDictionary and then load a new one and merge it into the dictionary that is built into the app class.

Let me know if you need code examples, because I do this in a few apps.


感谢Steve.

到目前为止,我喜欢您的解决方案.如果麻烦不大,那么不妨举一两个例子.

再次感谢.
Thanks Steve.

So far I like your solution. If it''s not much trouble an example or two would be very much appreciated.

Thanks again.


这篇关于如何在运行时在WPF应用程序中更改外观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆