WPF Multitrigger.ExitActions 将覆盖普通触发器 [英] WPF Multitrigger.ExitActions will override normal Trigger

查看:23
本文介绍了WPF Multitrigger.ExitActions 将覆盖普通触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无法解决的问题,所以我在这里寻求帮助.

I have a problem which im not able to solve, so im asking here to get some help.

这是导致我出现问题的代码的一部分:

This is a part of code which is causing me problem:

<Style.Triggers>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="IsSelected" Value="False"/>
                <Condition Property="IsMouseOver" Value="True"/>
            </MultiTrigger.Conditions>
            <MultiTrigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation To="#E1E1E1"
                                         Storyboard.TargetProperty="(TabItem.Background).(SolidColorBrush.Color)"
                                         Duration="00:00:00.3"/>
                    </Storyboard>
                </BeginStoryboard>
            </MultiTrigger.EnterActions>
            <MultiTrigger.ExitActions>
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation To="#F2F2F2"
                                         Storyboard.TargetProperty="(TabItem.Background).(SolidColorBrush.Color)"
                                         Duration="00:00:00.3"/>
                    </Storyboard>
                </BeginStoryboard>
            </MultiTrigger.ExitActions>
        </MultiTrigger>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="#3090C7" />
            <Setter Property="Foreground" Value="#F2F2F2" />
            <Setter Property="BorderThickness" Value="0" />
        </Trigger>
    </Style.Triggers>

我想要做的是,当我将鼠标悬停在一个 tabitem(未选中)上时,背景会淡化为深灰色,而当鼠标离开时,深灰色应淡化回较浅的颜色.这工作正常(如您所见,使用多触发器),但问题是当我单击选项卡项(未选中)时,tabitem 将更改为 isSelected 触发器样式,持续 0.1 秒,然后 Multitrigger.ExitActions 将覆盖样式和 tabitem会变成深灰色.

What I want to do is when i mouseover an tabitem (which is NOT selected) the background fade to darker gray and when mouse leaves the dark gray color should fade back to lighter one. This is working fine (using multitriggers as u can see), but the problem is when i click tab item (not selected one) the tabitem will change to isSelected trigger style for like 0.1 second and then Multitrigger.ExitActions will override the style and tabitem will turn to dark gray color.

我的母语不是英语!我试图尽可能好地描述我的问题.感谢所有愿意帮助我的人.

Im not native english speaker! I tried to desribe my problem as good as i can. Thanks to everyone who will try to help me out.

推荐答案

ExitActions 故事板中的 ColorAnimation 中,删除 To 值.这意味着动画将发生,但目标值将是当前设置的值 - 在这种情况下,通过 IsSelected 触发器的样式更改获取的值.您的代码应如下所示:

In the ColorAnimation within your ExitActions storyboard, remove the To value. This means that the animation will take place, but the target value will be the currently set one - in this case the one acquired by the style change of the IsSelected trigger. Your code should look like this:

<Style.Triggers>
    <MultiTrigger>
        <MultiTrigger.Conditions>
            <Condition Property="IsSelected" Value="False"/>
            <Condition Property="IsMouseOver" Value="True"/>
        </MultiTrigger.Conditions>
        <MultiTrigger.EnterActions>
            <BeginStoryboard>
                <Storyboard>
                    <ColorAnimation To="#E1E1E1"
                                    Storyboard.TargetProperty="(TabItem.Background).(SolidColorBrush.Color)"
                                    Duration="00:00:00.3"/>
                </Storyboard>
            </BeginStoryboard>
        </MultiTrigger.EnterActions>
        <MultiTrigger.ExitActions>
            <BeginStoryboard>
                <Storyboard>
                    <ColorAnimation Storyboard.TargetProperty="(TabItem.Background).(SolidColorBrush.Color)"
                                    Duration="00:00:00.3"/>
                </Storyboard>
            </BeginStoryboard>
        </MultiTrigger.ExitActions>
    </MultiTrigger>
    <Trigger Property="IsSelected" Value="True">
        <Setter Property="Background" Value="#3090C7" />
        <Setter Property="Foreground" Value="#F2F2F2" />
        <Setter Property="BorderThickness" Value="0" />
    </Trigger>
</Style.Triggers>

我实际上并没有检查此代码是否 100% 正确.如果它不起作用,请随时通知我.如果你想了解更多关于依赖属性的值优先级的信息,请阅读这篇文章:http://msdn.microsoft.com/en-us/library/ms743230(v=vs.110).aspx

I didn't actually check if this code is 100% correct. If it does not work, please feel free to inform me about it. If you want more information on value precedence of dependency properties, please read this article: http://msdn.microsoft.com/en-us/library/ms743230(v=vs.110).aspx

这篇关于WPF Multitrigger.ExitActions 将覆盖普通触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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