CompositionTarget.Rendering CompositionTarget.Rendering CompositionTarget.Rendering CompositionTarget.Rendering Event


Occurs when the core rendering process renders a frame.

public : event EventHandler<Platform::Object> Rendering
// Register
event_token Rendering(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void Rendering(event_token const& cookie) const;

// Revoke with event_revoker
Rendering_revoker Rendering(auto_revoke_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler<object> Rendering
Public Event Rendering As EventHandler (Of object)


Handling Rendering is mainly interesting if you have interop scenarios with Microsoft DirectX content. For example you might want to know when the XAML system is rendering and synchronize that with your Microsoft DirectX generated content and when your SwapChainPanel draws. For more info, see DirectX and XAML interop.

Because this event is for an interop scenario, it's rare that you would handle Rendering in C# or Microsoft Visual Basic code. You'd usually only handle it in the Visual C++ component extensions (C++/CX) code that supports the XAML portion of your UI, as part of an interop/hybrid app that also has a Microsoft DirectX component.

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. It's 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 interop content are loaded, and then remove the handler as part of page cleanup (OnNavigatedFrom ).

For example code of handling Rendering, see shooting game sample. The App::OnRendering method in this sample is the handler. This handler is noteworthy because it has code in it that checks its own UI state (such as checking for whether the control has focus). For certain states the handler acts as its own one-time cleanup by calling ::remove with an app-level stored event token from the initial ::add.

See also