CompositionTarget.Rendering Event

Definition

Occurs when the core rendering process renders a frame.

// Register
static event_token Rendering(EventHandler<IInspectable> const& handler) const;

// Revoke with event_token
static void Rendering(event_token const* cookie) const;

// Revoke with event_revoker
static CompositionTarget::Rendering_revoker Rendering(auto_revoke_t, EventHandler<IInspectable> const& handler) const;
public static event System.EventHandler<object> Rendering;
function onRendering(eventArgs) { /* Your code */ }
Windows.UI.Xaml.Media.CompositionTarget.addEventListener("rendering", onRendering);
Windows.UI.Xaml.Media.CompositionTarget.removeEventListener("rendering", onRendering);
- or -
Windows.UI.Xaml.Media.CompositionTarget.onrendering = onRendering;
Public Shared Custom Event Rendering As EventHandler(Of Object) 

Event Type

Remarks

Handling Rendering can be useful if you have interop scenarios with Microsoft DirectX content. For example you might want to know when the XAML framework is rendering a frame and synchronize that with your Microsoft DirectX generated content in a SwapChainPanel or SurfaceImageSource so visual updates are presented to the screen at the same time. For more info, see DirectX and XAML interop.

To satisfy the compiler, the second e/args parameter of your handler for a Rendering event must be Object. Don't use EventArgs. However, within the handler, you can cast the e/args reference as RenderingEventArgs. RenderingEventArgs has one property, RenderingTime, that might be useful in your rendering scenario, but not all handlers would need this info. It may be enough just to know that the event fires and handle every occurrence.

Handlers for Rendering run on the UI thread even though they're not tied to any specific UI element. This is similar to running an infinite animation. Normally the UI thread is active only when there is work to do, but adding a handler for this event forces it to run every frame which can prevent system power usage optimizations. It's therefore a good idea to remove any Rendering handlers when you no longer need them, and add them only when you do need them. For example add the handler only when specific pages with synchronized DirectX content are loaded, and then remove the handler as part of page cleanup (OnNavigatedFrom). For more information see the Use infinite animations sparingly section of the performance guide.

Applies to

See also