MouseOver 高亮显示样式在一秒钟后恢复为默认值(由 Aero 引起?) [英] MouseOver highlighting style returning to default after a second (Caused by Aero?)

查看:13
本文介绍了MouseOver 高亮显示样式在一秒钟后恢复为默认值(由 Aero 引起?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设计我的组合框的样式以匹配 UI 的其余部分,但我在 IsMouseOver 突出显示方面遇到了问题.它以我指定的颜色高亮显示一秒钟,然后淡入默认颜色,这是一种很酷的效果,但不是我想要的.这是我的风格:

I'd trying to style my ComboBoxes to match the rest of the UI but I'm having problems with the IsMouseOver highlighting. It highlights with the color I specify for a second and then fades back to the default color, kind of a cool effect but not what I'm going for. Here is my style:

<Style TargetType="ComboBox">
    <Style.Triggers>
        <Trigger Property="ComboBox.IsMouseOver" Value="True">
            <Setter Property = "Background" Value="Red"/>
        </Trigger>
    </Style.Triggers>
</Style>

如何才能使背景颜色保持不变?

What can I do to make the background color stay?

推荐答案

问题确实是由于 ComboBox 的默认模板造成的.如果您使用 Reflector 打开 PresentationFramework.Aero 程序集,您可以查看ButtonChrome 类.有一个叫做 OnRenderMouseOverChanged 的​​方法可以隐藏红色背景.

The problem is indeed due to the default template for the ComboBox. If you use Reflector to open the PresentationFramework.Aero assembly you can take a look at the ButtonChrome class. There is a method called OnRenderMouseOverChanged that is hiding the Red background.

即使工作量很大,至少对于 ComboBox,您可能希望覆盖 ComboBox 的默认模板.您可以使用 Show Me The模板混合.

Even though it is a lot of work, for ComboBox at least, you probably will want to override the default template for the ComboBox. You can get the basic idea of what the ComboBox temlpate is like by using Show Me The Template or Blend.

您可以使用相同的样式来覆盖模板.

You can use your same style to override the template.

<Style TargetType="{x:Type ComboBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ComboBox}">
                <!-- Template Here -->
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

这篇关于MouseOver 高亮显示样式在一秒钟后恢复为默认值(由 Aero 引起?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆