Sonhja
Sonhja

Reputation: 8458

Animation not firing last part

I have the following code:

<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>

This acts like a counter, from 3 to 1. Everything works fine, except from the last part. The Panel disappear is not working. It should make the panel invisible, but it's still there...

What I'm doing wrong?

NOTE: I call the storyboard like this:

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

Upvotes: 1

Views: 30

Answers (1)

dkozl
dkozl

Reputation: 33384

Your last animation has a Duration of 0:0:0 yet you set KeyTime to 0:0:3 which is beyond duration time. You can change KeyTime to 0:0:0 and set BeginTime to 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>

Upvotes: 1

Related Questions