Silverlight 2 Per-Frame Rendering Callback – CompositionTarget.Rendering Event
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.