开发者

Using WPF StoryBoard Forward and Reverse

开发者 https://www.devze.com 2023-01-10 02:27 出处:网络
I need help in the Storyboard Seek. The following code is not working: Storyboard StoryBoard; public void 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.FromMilliseco开发者_C百科nds(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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号