当鼠标悬停在WPF ComboBox的顶部时,是否有人知道如何设置WPF ComboBox的背景属性?
我无法摆脱ComboBox背景下的蓝色按钮。
答案 0 :(得分:4)
你可以像其他任何东西一样设计样式:
<Style TargetType="{x:Type ComboBox}" x:Key="HoverBox">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Blue" />
</Trigger>
</Style.Triggers>
</Style>
用法:
<ComboBox Style="{StaticResource HoverBox}" ... />
在UserControl / Window的顶部,您必须放置样式:
<UserControl...>
<UserControl.Resources>
<Style TargetType="{x:Type ComboBox}" x:Key="HoverBox">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Blue" />
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
[CONTENT HERE]
</UserControl>
答案 1 :(得分:1)
它不会工作。因为ComboBox的默认控件模板。你可能需要覆盖此行为的默认模板。看看
MouseOver highlighting style returning to default after a second (Caused by Aero?)
http://social.expression.microsoft.com/Forums/en/blend/thread/b210978c-24e8-431b-916b-a40a752b990c
http://social.msdn.microsoft.com/Forums/en/wpf/thread/a18891e9-8879-4819-9679-247341782f60