【问题标题】:Unable to style WPF ComboBox on Mouse Hover无法在鼠标悬停时设置 WPF 组合框的样式
【发布时间】:2011-04-06 08:34:24
【问题描述】:

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

我无法摆脱 ComboBox 中的蓝色按钮(如背景)。

【问题讨论】:

    标签: c# wpf combobox


    【解决方案1】:

    您可以像其他任何东西一样设置样式:

    <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>
    

    【讨论】:

    • 我把样式放在你写的组合框中。但它在 x:Key 上给了我一个例外,说“Key 属性只能用于 IDictionary 类型属性中包含的标签”
    • 感谢您的努力。我按照你说的做了,但是组合框仍然有旧的按钮背景。
    • 您可以将 IsEditable 设置为 true...也许这就是您想要的?
    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 2016-04-27
    • 2021-10-08
    • 1970-01-01
    相关资源
    最近更新 更多