【发布时间】:2011-04-06 08:34:24
【问题描述】:
有谁知道当鼠标悬停在 WPF ComboBox 上时如何设置其背景属性的样式?
我无法摆脱 ComboBox 中的蓝色按钮(如背景)。
【问题讨论】:
有谁知道当鼠标悬停在 WPF ComboBox 上时如何设置其背景属性的样式?
我无法摆脱 ComboBox 中的蓝色按钮(如背景)。
【问题讨论】:
您可以像其他任何东西一样设置样式:
<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...>
<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>
【讨论】:
它不起作用。这是因为 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
【讨论】: