
Per-Frame Animation: Bypass the Animation and Timing System
Use this approach when you need to completely bypass the WPF animation system. One scenario for this approach is physics animations, where each step in the animation requires objects to be recomputed based on the last set of object interactions.
Per-frame animations cannot be defined inside styles, control templates, or data templates.
To animate frame-by-frame, you register for the Rendering event of the object that contains the objects you want to animate. This event handler method gets called once per frame. Each time that WPF marshals the persisted rendering data in the visual tree across to the composition tree, your event handler method is called.
In your event handler, perform whatever calculations are necessary for your animation effect and set the properties of the objects you want to animate with these values.
To obtain the presentation time for the current frame, the EventArgs associated with this event can be cast as RenderingEventArgs, which provide a RenderingTime property that you can use to obtain the current frame's rendering time.
For more information, see the Rendering page. For an example, see the Per-Frame Animation Sample.