-1

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?

ridilculous
  • 624
  • 3
  • 16
  • 1
    I guess you'll need to create a dispatcher queue controller ([`CreateDispatcherQueueController`](https://learn.microsoft.com/en-us/windows/win32/api/dispatcherqueue/nf-dispatcherqueue-createdispatcherqueuecontroller)), though frankly, I don't know what WinUI 3's Dispatcher-of-the-Week is this week. – IInspectable Sep 12 '22 at 11:37

1 Answers1

0

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.

Related issue.

Related Issue.

ridilculous
  • 624
  • 3
  • 16