使用WPF StoryBoard正向和反向

时间:2010-08-02 16:36:56

标签: c# wpf animation

我在Storyboard Seek中需要帮助。以下代码无效:

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

提前致谢。

2 个答案:

答案 0 :(得分:2)

反向:

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

前进:

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

答案 1 :(得分:0)

你可以简单地做到这一点

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