在多个程序集中应用全局样式
我的应用程序由相当多的程序集(“插件”)组成,这些程序集由核心可执行程序集(其本身不包含任何控件或窗口)加载。现在我想将中央程序集的 Application.Resources 样式中的样式应用于控件(例如菜单/上下文菜单、工具栏(托盘)等)(可能用户可以从多个主题中进行选择)。
我让它可以使用命名样式(x:Key="StyleName"
,由 DynamicResource
调用,StaticResource
不起作用),但是将 Style="{DynamicResource ...}"
添加到每个程序集中的每个控件的前景让我有点害怕。但无论我做什么,带有 TargetType="{x:Type TypeName}"
的控件范围样式都不起作用。
如何从一个中央组件集中设置所有控件的样式?
感谢您的帮助。
My application is composed from quite a few assemblies ("plug-ins") that are loaded by a core executable assembly (which doesn't contain any controls or windows on it own). Now I want to apply styles to controls (such as Menus/ContextMenus, ToolBar(Tray)s etc.) from the central assembly's Application.Resources styles (possibly with the option of users being able to choose from several themes).
I got it to work with named styles (x:Key="StyleName"
, invoked by DynamicResource
, StaticResource
wouldn't work), but the prospect of adding the Style="{DynamicResource ...}"
to every control in every assembly scares me quire a little bit. But the control-wide styles with TargetType="{x:Type TypeName}"
won't work no matter what I do.
How can I style all the controls en masse from one central assembly?
Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这篇关于 WPF 皮肤的精彩文章可能会帮助您指明正确的方向?
在简介中,他强调了换肤/主题化的“三大支柱”以及如何利用分层资源。
尽管我确实担心(不确定)您可能仍然需要将静态资源更改为动态资源。
Perhaps this great article on WPF skinning might help point you in the right direction?
In the intro, he highlights the "three pillars" for skinning/theming and how hierarchical resources can be leveraged.
Though I do fear (without certainty) that you might still need to change your static resources to dynamic ones.