简体   繁体   中英

How to get the compositor instance while handling XamlCompositionBrushBase.OnConnected in a WinUI-3 desktop app

Following this c++ example i'm trying to create a custom brush in a WinUI 3 desktop application but i cannot find out how to get a compositor instance from within the OnConnected Method . The example uses

Microsoft::UI::Xaml::Window::Current().Compositor()

but Current (and CoreWindow ) are always null for desktop apps .

How can i get the compositor instance needed to create brushes?

Ok, as often it gets easy as soon as the matching documentation is found:

In XAML apps, we recommend that you call ElementCompositionPreview.GetElementVisual(UIElement) to get a Composition Visual , and get the Compositor from the visual's Compositor property. In cases where you don't have access to a UIElement (for example, if you create a CompositionBrush in a class library), you can call CompositionTarget.GetCompositorForCurrentThread to get the Compositor instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM