如何加载 WPF 主题?
WPF 控件从主题(通常在PresentationFramework.Aero.dll 中)获取默认样式、颜色和画笔。
该组件由哪一部分加载?资源字典存储在哪里?
我有自己的 WPF 自定义主题并将它们加载到 Application.Current.Resources.MergedDictionary 中。 但是,如果 WPF 主题控件托管在 Windows 窗体中,则此方法不起作用,因为 Application.Current 为 null。
有没有办法做类似 WPF 的事情?如果是这样,那是什么?
WPF controls get their default styles, colors and brushes from a theme (Usually, in PresentationFramework.Aero.dll).
What piece of loads this assembly? And where are the resource dictionary stored?
I have my own WPF custom themes and load them in the Application.Current.Resources.MergedDictionary.
However, this does not work if the WPF themed control is hosted in Windows Forms since Application.Current is null.
Is there a way to do something similar to what WPF does? If so, what is it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能在 Winforms 中使用 WPF 主题,因为它们是两种不同的技术。 Winforms 本身没有类似的主题机制。您可以使用支持 Winforms 主题的第三方控件。其中最引人注目的是 Infragistics 和 Telerik 的工具。
底线答案是否定的,不存在。
You cannot use the WPF themes in Winforms because they are two different technologies. There isn't a similar theme mechanism in Winforms natively. You can use third-party controls that support themes in Winforms. The most notable of these are the tools from Infragistics and Telerik.
Bottom line answer is no, there isn't.
您可以尝试仅将主题添加到控件而不是应用程序吗?
Can you try just adding the theme to the control instead of the Application?
(回答我自己的问题)
将资源字典加载为主题的方法是将其添加到 generic.xaml 资源字典的合并字典列表中。
没有其他方法可以将资源字典加载为主题。
从 WinForms 使用时效果很好
(answering my own question)
The way to load a resource dictionary as a theme is to add it to the list of merged dictionaries of the generic.xaml resource dictionary.
There is no other way to load a resource dictionary as a theme.
This works fine when used from WinForms