Storyboard as timer in WPF

Posted by Adrian on Stack Overflow See other posts from Stack Overflow or by Adrian
Published on 2010-05-13T06:37:41Z Indexed on 2010/05/13 6:44 UTC
Read the original article Hit count: 269

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about storyboard