将主题应用到控件模板
到目前为止,基本上我的问题是我正在将控件模板修改为组合框,以便它看起来像我想要的那样。最重要的是,我们的整个项目都使用 ExpressionDark 主题。问题是,当我在 ComboBox 上设置样式以使其使用修改后的模板时,其 ExpressionDark 样式会被覆盖。
我能想到的唯一解决方案是尝试删除模板中的任何显式着色,但这不起作用。还有 OnApplyTemplate() 但我不确定应该如何使用它。
有人对我如何解决这个问题有一些建议吗?
谢谢
Basically my problem so far is I'm modifying the control template to a ComboBox so that it looks the way I want it to. On top of that our entire project is using the ExpressionDark theme. The problem is that when I set the style on the ComboBox so it uses my modified template its ExpressionDark styling gets overridden.
The only solutions I could think of was to try and take out any explicit coloring in the template but that didn't work. There's also the OnApplyTemplate() but I'm not sure how I should use this.
Does anybody has some advice on how I could go about this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将自定义样式基于 Expression Dark 主题应用的隐式样式。一个元素只能应用一种隐式样式。最重要的是,如果显式设置 Style 属性,则不会应用隐式 Style。
因此,如果您有 Expression Dark 主题的隐式样式:
以及自定义样式,例如:
并像这样使用它:
那么您需要将 MyStyle 更改为基于隐式样式,因此它的 Setters 和 Triggers 也适用所以:
这显然要求可以从定义自定义样式的位置访问隐式样式资源。如果隐式样式位于应用程序资源中,那么您应该很好。
编辑:
由于您使用的是 Silverlight,因此不支持
x:Type
部分。您需要修改 Expression Dark 主题才能使其正常工作。因此,如果您有 Expression Dark 主题的隐式样式:
您需要将其分成两个样式,如下所示:
然后您的自定义样式需要像这样进行修改:
隐式样式中不应包含任何 Setter。一切都应该在 ComboBoxBaseStyle 版本中完成。
You would need to base your custom Style on the implicit Style applied by the Expression Dark theme. You can only have one implicit Style applied to an element. On top of that, if you set the Style property explicitly then no implicit Style will be applied.
So if you have the implicit Style for the Expression Dark theme:
And a custom Style like:
And use it like so:
Then you'd need to change MyStyle to be based on the implicit Style, so it's Setters and Triggers are also applied like so:
This obviously requires that the implicit Style resource be accessible from where you define your custom Style. If the implicit Style is in the application resources, then you should be good.
EDIT:
Since you are using Silverlight, the
x:Type
part is not supported. You'd need to modify the Expression Dark theme to get this to work.So if you have the implicit Style for the Expression Dark theme:
You would need to break it out into two Styles like so:
Then your custom Style would need to be modified like so:
The implicit Style should not have any Setters in it. Everything should be done in the ComboBoxBaseStyle version.