Welcome to Pete Brown's 10rem.net

First time here? If you are a developer or are interested in Microsoft tools and technology, please consider subscribing to the latest posts.

You may also be interested in my blog archives, the articles section, or some of my lab projects such as the C64 emulator written in Silverlight.

(hide this)

Silverlight 2 Per-Frame Rendering Callback – CompositionTarget.Rendering Event

Pete Brown - 29 September 2008

While promised early on, this one seemingly snuck in under the radar :)

Silverlight 2 now has the CompositionTarget.Rendering event.

So now, if you want to do something each frame, this is one place where you can do it. You’ll want to do some testing to see just how much you can pack in there before causing problems for your app.

Where would you use this? On possibility would be when you need to build up the display for some complex animation or a gameloop. If you don’t have your gameloop synchronized exactly with the rendering system, you may be doing more work (drawing things twice, for example) or not enough work (drawing only once every three frames). Granted, you are tied to the frames-per-second in this case, and not to a timer, but sometimes that’s exactly what you want.

CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
void CompositionTarget_Rendering(object sender, EventArgs e)
{
    // do something each frame
}

It's as simple as that.

   
posted by Pete Brown on Monday, September 29, 2008
filed under:    

1 comment for “Silverlight 2 Per-Frame Rendering Callback – CompositionTarget.Rendering Event”

  1. Andrew Lsays:
    Belated thanks for this great news! I've become quite accustomed to designing animation-orientated WPF applications around the Rendering event, so I was more than a little worried when it was omitted from Silverlight 1.0. I'm very pleased that Microsoft has added it to Silverlight 2.0.

Comment on this Post

Remember me

1 trackback for “Silverlight 2 Per-Frame Rendering Callback – CompositionTarget.Rendering Event”

  1. 2008 September 30 - Links for today « My (almost) Daily Linkssays:
    PingBack from http://mgalinks.wordpress.com/2008/09/30/2008-september-30-links-for-today/