为什么在触发器中设置 Button.Background 不起作用?
以下 MultiTrigger 工作正常,但如果我尝试将 Button.Background 更改为红色,则它不起作用。有什么想法吗?
<Window.Resources>
<Style TargetType="Button">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions >
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsFocused" Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="FontWeight" Value="Bold" />
</MultiTrigger.Setters>
</MultiTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
The following MultiTrigger works fine but if I try to Change Button.Background to Red, its not working. Any thoughts?
<Window.Resources>
<Style TargetType="Button">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions >
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsFocused" Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="FontWeight" Value="Bold" />
</MultiTrigger.Setters>
</MultiTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
属性由优先级列表设置,这意味着某些属性将覆盖您的<代码>样式属性。
因此,请检查您是否直接在
Button
上设置了Background
,因为这会覆盖您的Style
背景设置器;您可能还想考虑使用默认背景的样式,如下所示:Properties are set by a Precedence List, meaning some properties will overwrite your
Style
properties.So check if you have set a
Background
directly on yourButton
, because this will overwrite yourStyle
background setter; you might want to consider using the Style for your default background as well, like so:发生这种情况是因为 Button 的 ControlTemplate。如果我将操作系统主题从 Luna 更改为 Windows XP,效果很好。查看这些链接
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b23e8641-977f-4127-a96a-d329a1ba04e4/
http://www.wiredprairie.us/journal/2006/09/wpf_decorators_build_your_own.html
This is happening because of Button's ControlTemplate. If I change my OS theme to Windows XP from Luna this works fine. Take a look at these links
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b23e8641-977f-4127-a96a-d329a1ba04e4/
http://www.wiredprairie.us/journal/2006/09/wpf_decorators_build_your_own.html