首页 新闻 搜索 专区 学院

WPF 动画的控制,等待上一个动画完成后再执行下一个动画

0
悬赏园豆:100 [已关闭问题] 关闭于 2012-07-29 16:36

动画是用Blend 4做的,动画是这样的,一个控件,鼠标一移上去的时候,控件左移一段距离,鼠标移开的时候,控件从左边回到原来的位置,好,问题出现了,当鼠标移动到控件上停留一段时间的话,那么左移的动作是可以完全做完,再移开的时候,右移的动作也能完全完成,但是,当鼠标很快的完成一次“MouseEnter”和“MouseLeave”的时候,左移动作还没做完,就开始右移了,下面是Blend 4生成的代码,请问xaml有没有一个机制可以直接解决这个问题的,或哪位前辈帮忙想想其他方法,谢谢啦!

<EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="slider">
            <BeginStoryboard x:Name="sound_in_BeginStoryboard" Storyboard="{StaticResource sound_in}"/>
            <BeginStoryboard x:Name="sound_in_time_BeginStoryboard" Storyboard="{StaticResource sound_in_time}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="slider">
            <BeginStoryboard x:Name="sound_out_BeginStoryboard" Storyboard="{StaticResource sound_out}"/>
            <BeginStoryboard x:Name="sound_out_time_BeginStoryboard" Storyboard="{StaticResource sound_out_time}"/>
        </EventTrigger>
UncleNull的主页 UncleNull | 初学一级 | 园豆:3
提问于:2012-07-29 02:37
< >
分享
所有回答(2)
0

额...出现这种问题不是技术无法实现,而是思路不对,从而把自己逼进一些奇怪的实现方法当中,其实问题的根本在于解决瞬间移动的问题,就是上述的左移还没完成,瞬间跳到最左边开始右移,我们只要把初始状态删掉

原代码如下

<EasingThicknessKeyFrame KeyTime="0" Value="-445,100,0,0"/>
<EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="0,100,0,0">

修改为

<EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="0,100,0,0">

就没有起始状态了,于是乎效果就是控件只会在这两个值之间来回跑,而不会出现瞬间跳位置的现象

把源码贴上,可以把注释的行取消对比下效果

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="动画是否结束.MainWindow"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480">
    <Window.Resources>
        <Storyboard x:Key="In">
            <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="button1">
                <!--<EasingThicknessKeyFrame KeyTime="0:0:0" Value="0,100,0,0"/>-->
                <EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="-445,100,0,0">
                    <EasingThicknessKeyFrame.EasingFunction>
                        <BackEase EasingMode="EaseInOut" Amplitude="0"/>
                    </EasingThicknessKeyFrame.EasingFunction>
                </EasingThicknessKeyFrame>
            </ThicknessAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="Out">
            <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="button1">
                <!--<EasingThicknessKeyFrame KeyTime="0:0:0" Value="-445,100,0,0"/>-->
                <EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="0,100,0,0">
                    <EasingThicknessKeyFrame.EasingFunction>
                        <BackEase EasingMode="EaseInOut" Amplitude="0"/>
                    </EasingThicknessKeyFrame.EasingFunction>
                </EasingThicknessKeyFrame>
            </ThicknessAnimationUsingKeyFrames>
        </Storyboard>
    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="button">
            <BeginStoryboard x:Name="In_BeginStoryboard" Storyboard="{StaticResource In}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="button">
            <BeginStoryboard x:Name="Out_BeginStoryboard" Storyboard="{StaticResource Out}"/>
        </EventTrigger>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded"/>
    </Window.Triggers>
    <Grid x:Name="LayoutRoot">
        <Button x:Name="button" Content="Hello" Width="100" Height="50"></Button>
        <Button x:Name="button1" Content="Heaven" Width="100" Height="50" Margin="0,100,0,0">
        </Button>
    </Grid>
</Window>
UncleNull | 园豆:3 (初学一级) | 2012-07-29 16:36
0

这是自问自答么????

羽商宫 | 园豆:2493 (老鸟四级) | 2012-07-29 22:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册