c# - 无法在鼠标悬停时设置 WPF ComboBox 的样式

标签 c# wpf combobox

有谁知道当鼠标悬停在 WPF ComboBox 上时如何设置其背景属性的样式?

enter image description here

我无法摆脱像 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>

关于c# - 无法在鼠标悬停时设置 WPF ComboBox 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5563536/

相关文章:

c# - 组合框下拉列表

c# - 如何检测图像中的黑色子弹?

c# - system.drawing.image 到 spfile

wpf - WPF RichTextBox和'\t'

wpf - 自定义 UIElement 是否可以实现 IList<UIElement> 并直接分配子项(在 XAML 中)?

user-interface - 自动完成与下拉菜单。什么时候使用?

c# - 表达式树 : iterate through strings and check if they contained in another Expression

c# - 从 C# 提交 Spark 作业并获得结果

c# - 如何将单元格集中在 WPF DataGrid 中的新行

JAVA 或我的 IDE 的限制或 SQL 问题?