Britto Raj
Britto Raj

Reputation: 35

Using WPF StoryBoard Forward and Reverse

I need help in the Storyboard Seek. The following code is not working:

Storyboard StoryBoard;

public void Reverse()
            {
                StoryBoard.Pause(this);

                TimeSpan ts = new TimeSpan(0);
                ts.Subtract(TimeSpan.FromMilliseconds(1000));
                StoryBoard.Seek(this, ts, TimeSeekOrigin.BeginTime);
            }

public void Forward()
            {
                StoryBoard.Pause(this);

                TimeSpan ts = new TimeSpan(0);
                ts.Add(TimeSpan.FromMilliseconds(1000));
                StoryBoard.Seek(this, ts, TimeSeekOrigin.BeginTime);
            }

Thanks In Advance.

Upvotes: 0

Views: 1950

Answers (2)

Uchenna Nnodim
Uchenna Nnodim

Reputation: 484

you could simply do this

 Storyboard anime = (Storyboard)FindResource("Storyboard1");
        TimeSpan ts = new TimeSpan(0);
        anime.Seek(ts);
        anime.Stop();

Upvotes: 0

Britto Raj
Britto Raj

Reputation: 35

For Reverse:

TimeSpan CurrentTime = (TimeSpan) StoryBoard.CurrentTime;
TimeSpan SubtractTime = CurrentTime.Subtract(new TimeSpan(FrameRate * (long)Math.Pow(10,4)));
StoryBoard.Seek(SubtractTime, TimeSeekOrigin.Duration);

For Forward:

TimeSpan CurrentTime = (TimeSpan) StoryBoard.CurrentTime;
TimeSpan AddTime = CurrentTime.Add(new TimeSpan(FrameRate * (long)Math.Pow(10,4)));
StoryBoard.Seek(AddTime, TimeSeekOrigin.Duration);

Upvotes: 2

Related Questions