动画没有触发最后一部分

时间:2014-11-04 12:04:23

标签: wpf xaml animation wpf-animation

我有以下代码:

<Storyboard x:Key="CounterStoryboard" >

    <!-- Panel appear -->
    <ObjectAnimationUsingKeyFrames Duration="0:0:0" Storyboard.TargetName="CounterPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
    </ObjectAnimationUsingKeyFrames>

    <!-- 3-->
    <DoubleAnimation 
        Storyboard.TargetProperty="(UIElement.Opacity)" 
        Storyboard.TargetName="CounterLabel3" From="1" To="0" Duration="0:0:1" BeginTime="0:0:0">
    </DoubleAnimation>

    <!-- 2 -->
    <DoubleAnimation 
        Storyboard.TargetProperty="(UIElement.Opacity)" 
        Storyboard.TargetName="CounterLabel2" From="0" To="1" Duration="0:0:0" BeginTime="0:0:1">
    </DoubleAnimation>
    <DoubleAnimation 
        Storyboard.TargetProperty="(UIElement.Opacity)" 
        Storyboard.TargetName="CounterLabel2" From="1" To="0" Duration="0:0:1" BeginTime="0:0:1">
    </DoubleAnimation>

    <!-- 1 -->
    <DoubleAnimation 
        Storyboard.TargetProperty="(UIElement.Opacity)" 
        Storyboard.TargetName="CounterLabel1" From="0" To="1" Duration="0:0:0" BeginTime="0:0:2">
    </DoubleAnimation>
    <DoubleAnimation 
        Storyboard.TargetProperty="(UIElement.Opacity)" 
        Storyboard.TargetName="CounterLabel1" From="1" To="0" Duration="0:0:1" BeginTime="0:0:2">
    </DoubleAnimation>

    <!-- Panel disappear -->
    <ObjectAnimationUsingKeyFrames Duration="0:0:0" Storyboard.TargetName="CounterPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
        <DiscreteObjectKeyFrame KeyTime="0:0:3" Value="{x:Static Visibility.Collapsed}"/>
    </ObjectAnimationUsingKeyFrames>
</Storyboard>

这就像一个计数器,从3到1.一切正常,除了最后一部分。 Panel disappear无效。它应该使面板不可见,但它仍然存在......

我做错了什么?

注意:我将故事板称为:

sb = (Storyboard)FindResource("CounterStoryboard");
sb = sb.Clone();
sb.Completed += sb_Completed;
sb.Begin(this);

1 个答案:

答案 0 :(得分:1)

您的上一个动画的Duration为0:0:0但是您将KeyTime设置为0:0:3,这超出了持续时间。您可以将KeyTime更改为0:0:0并将BeginTime设置为0:0:3

<ObjectAnimationUsingKeyFrames Duration="0:0:0" BeginTime="0:0:3" Storyboard.TargetName="CounterPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
    <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Collapsed}"/>
</ObjectAnimationUsingKeyFrames>