触发EventTrigger后触发不会触发

时间:2012-03-14 20:12:29

标签: c# wpf xaml triggers eventtrigger

所以我试图制作一个按钮,当鼠标翻转/关闭/向上/向上时会改变图像....

并提出以下建议:

<Image>
    <Image.Style>
        <Style TargetType="{x:Type Image}">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="True">
                    <Setter Property="Source" Value="/MyWPF;component/Resources/MediaPlayer/Play-Normal-icon.png"/>
                </Trigger>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Source" Value="/MyWPF;component/Resources/MediaPlayer/Play-Pressed-icon.png"/>
                </Trigger>
                <Trigger Property="IsMouseOver" Value="False">
                    <Setter Property="Source" Value="/MyWPF;component/Resources/MediaPlayer/Play-Normal-icon.png"/>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Source" Value="/MyWPF;component/Resources/MediaPlayer/Play-Disabled-icon.png"/>
                </Trigger>
                <EventTrigger RoutedEvent="MouseDown">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="Source" Duration="00:00:00.5">
                                    <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                        <DiscreteObjectKeyFrame.Value>
                                            <BitmapImage UriSource="/MyWPF;component/Resources/MediaPlayer/Play-Hot-icon.png"/>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
                <EventTrigger RoutedEvent="MouseUp">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="Source" Duration="00:00:00.5">
                                    <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                        <DiscreteObjectKeyFrame.Value>
                                            <BitmapImage UriSource="/MyWPF;component/Resources/MediaPlayer/Play-Normal-icon.png"/>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </Image.Style>
</Image>

鼠标过度/完全正常工作。

但是一旦我点击(向下)鼠标,触发了EventTriggers,我可以看到图像已经改变。

释放鼠标单击(向上),再次触发EventTriggers,我可以看到图像改变回原来的样式。

现在我将图像鼠标移出/移出。它不再改变图像......

但是,当我按下/向上鼠标仍在工作时......

所以我在猜怪EventTrigger是否覆盖了IsMouseOver触发器?

EventTrigger会覆盖其他触发器吗?

P.S。:对于那些读过我之前的问题的人,抱歉,我不知道问题是由于数据绑定中的Button被禁用引起的。

1 个答案:

答案 0 :(得分:2)

这是因为dependency property value precedence,要么更改其他触发器以导致单帧动画,要么使动画不是hold their value