简体   繁体   中英

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.

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

you could simply do this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM