views:

120

answers:

2

Is there a simple way to play some StoryBoad backward (reversed) ? As there is a method Storyboard.Begin() I would expect that there is some method like "Storyboard.BeginReversed()" but I cannot find it.

If there is no way to play an animation backwards that I have to write for most of my animations complementary animations. That smells bad to me (code duplication of some kind).

Basically I just animate a Grid that shows and than hides.

+1  A: 

Can you flip the "From" and "To" and play it again?

Kai Wang
Thank you for answer. OK that's the way... But it is not very clear. The thing is that you have to keep somewhere an information that you have flipped them. I would rather have something clearer. There is really no method for this, no the creators of `Storyboard` did not think about this ??
drasto
@drasto- I think if you wants to play an animation reversely, the designer treats it as a different animation. It's up to you to make creating such an animation easier. Of course you can always write extension methods to extend the storyboard you are using to make it cleaner.
Kai Wang
Thank you. I'll try to write extension method but it will not be easy. I will have to take care about such thinks as invoking backward animation while forward animation is still running and similar.
drasto
@draso, post your animation code.
Kai Wang
There is no better answer and I don't thing there is better approach then flipping From and To, so I accept this answer.
drasto
A: 

I think this will help you (see also xaml example below)

var storyboard = this.Resources["Storyboard1"] as Storyboard;

        var anim = storyboard.Children[0] as DoubleAnimationUsingKeyFrames;

        anim.AutoReverse = true;

        anim.RepeatBehavior = RepeatBehavior.Forever;

<Storyboard x:Key="Storyboard1">
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="border" Storyboard.TargetProperty="(FrameworkElement.Width)">
            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="200"/>
            <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="300"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
Daniel Bern
Sorry I don't want to AutoRepeat it I want to play it backwards, maybe later after original play was finished.
drasto