I want to create a window with acrylic style. I had read the code on WinUI3 Gallery and tried to use AddSystemBackdropTarget() to achieve that.
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
// m_window = WindowHelper.CreateWindow();
m_window = new Window();
Frame rootFrame = GetRootFrame(args);
// if (m_window.DispatcherQueue != null) // ture
DesktopAcrylicController acrylicController = new();
acrylicController.AddSystemBackdropTarget(m_window.As<ICompositionSupportsSystemBackdrop>());
m_window.Activate();
}
PS: I'm using the template of WinUI3 which was created by Visual Studio.
The exception was:
exception info
About my machine:
OS: Window 11, version 22H2
Windows SDK: Microsoft.WindowsAppRuntime.1.2
I have noticed that the AddSystemBackdropTarget() method must be called on a thread with a DispatcherQueue, so I checked the property to ensure it's not null.
And I also tried TryEnqueue() method to add the AddSystemBackdropTarget() task to the DispatcherQueue. But none of them could solve my problem.