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.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();
精彩评论