Storyboard as timer in WPF
- by Adrian
Hi,
I'm trying to do smooth animation in procedural code. For this (in Silverlight at least), it's recommended to use the Storyboard timer rather than a DispatcherTimer.
So I use something like this:
Storyboard _LoopTimer = new Storyboard();
public void StartAnimation()
{
_LoopTimer.Duration = TimeSpan.FromMilliseconds(0);
_LoopTimer.Completed += new EventHandler(MainLoop);
_LoopTimer.Begin();
}
void MainLoop(object sender, EventArgs e)
{
// Do animation stuff here
// Continue storyboard timer
_LoopTimer.Begin();
}
And in Silverlight, this works fine. But in WPF, I only hit MainLoop() once. Setting RepeatBehaviour to Forever doesn't help, either.
So what's the right way to do this in WPF with a Storyboard?
Thanks very much.