WPF组合框鼠标悬停
当鼠标悬停在其上方时,如何设置组合框样式以使其看起来像这样?
How can I setup a Combobox Style to make it look like this when mouse is hovering over it?
当前,它看起来像这样:
Currently, it looks like this:
我尝试过:
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="White" />
</Trigger>
</Style.Triggers>
但这没有用。
更新,这是我右键单击组合框时的内容:
Update, this is what I have when I right-click on the combobox:
Blend给了我这些颜色:
Blend gave me these colors:
<SolidColorBrush x:Key="ComboBox.MouseOver.Glyph" Color="#FF000000"/>
<LinearGradientBrush x:Key="ComboBox.MouseOver.Background" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFECF4FC" Offset="0.0"/>
<GradientStop Color="#FFDCECFC" Offset="1.0"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#FF7EB4EA"/>
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Background" Color="#FFFFFFFF"/>
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Border" Color="#FF7EB4EA"/>
<LinearGradientBrush x:Key="ComboBox.MouseOver.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFEBF4FC" Offset="0.0"/>
<GradientStop Color="#FFDCECFC" Offset="1.0"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Border" Color="#FF7EB4EA"/>
这些是您得到的蓝色。
如果右键单击组合框
,然后编辑模板->编辑副本...
,您应该可以将颜色更改为所需的颜色。查找 MouseOver
条目。
These are the blue colors you are getting.
If you right click the ComboBox
then Edit Template -> Edit a Copy...
you should be able to change the color to whatever you want. Look for MouseOver
entries.
可以将代码插入您喜欢的任何位置。在我的示例中,它位于< Window.Resources>
:
The code can be inserted anywhere you like it. In my example it is inside <Window.Resources>
:
<Window.Resources>
...
<SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#FF7EB4EA"/>
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Background" Color="#FFFFFFFF"/>
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Border" Color="#FF7EB4EA"/>
<LinearGradientBrush x:Key="ComboBox.MouseOver.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFEBF4FC" Offset="0.0"/>
<GradientStop Color="#FFDCECFC" Offset="1.0"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Border" Color="#FF7EB4EA"/>
...
</Window.Resources>
这只是一个例子!
这是一个相当大的代码段,但这是您要更改的部分。
It's a rather big code snippet, but this is the part you want to change.