|Controlling the animation|
I had previously, and erroneously claimed that it was not possible to step through an animation, as you would if you were stepping from frame to frame in a cell animation. It's quite easy when you know how. Unfortunately, it took me quite a long while to find out how.
It is as easy as this:
TimeSpan seekTime = new TimeSpan(0,0,0,(int)e.NewValue/1000,(int)e.NewValue%1000); storyboard.Begin(this, true); // if the second parameter is missing or false, it doesn't work storyboard.Seek(this, seekTime, TimeSeekOrigin.BeginTime); storyboard.Pause(this); // stop doesn't work
This code is triggered by the dragging the slider in the diagram below.
Those of you with Charles Petzold's book might recognise it. See below.
Click here to download the project files
|A couple of plugs|
The code above is a small change to one of Charles Petzold's examples. His book has come under a lot of fire for not being full of pictures, so I'd like to share a few thoughts on the matter:
I own two books on WPF. Adam Nathan's book got me started. It is an excellent, well written and well presented book, with the right knowledge at the right time for a starter. Petzold's book comes from a different angle, and while it could be used for starting, it is not as immediately friendly as Nathan's.
Yet Petzold's book sits on the top of the heap. When I need an answer, that's where I go looking.
The second plug is a thank you to jean-claude manoli at manoli.net, for the c# formatting for the web.