Share via


WPF Animation with CompositionTarget.Rendering

CompositionTarget.Rendering provides the ability to render directly to the screen on per frame basis, potentially 60 times a second or more depending on the refresh rates of the computer monitor. As MSDN documentation pointed out, this event handler gets called whenever WPF rendering process happens.

Here is simple spinning circle animation as a demonstration. The approach is very simple, whenever the rendering event is called from WPF process, the inner two circle geometry will be recreated and drawing straight onto the screen.

Limitations of CompositionTarget.Rendering
As it's a static event, it keeps firing even if control you use it in isn't on the screen any more.  Therefore, it is crucial to unregister when the control is unloaded, or the visual element is not visible such as window is minimized.

Sample Code