I am making a WinUI 3 app in C++. I tried setting the backdrop of the window to acrylic but it does not work. It crashes with the exception "hresult_error" when calling AddSystemBackdropTarget. I could not find out why this is.
Code:
void MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
auto m_configurationSource = Microsoft::UI::Composition::SystemBackdrops::SystemBackdropConfiguration();
auto m_Target = this->try_as<Microsoft::UI::Composition::ICompositionSupportsSystemBackdrop>();
auto desktopAcrylicController = Microsoft::UI::Composition::SystemBackdrops::DesktopAcrylicController();
if (m_Target == nullptr) {
MessageBox(NULL, L":(", L":(", MB_OK);
}
desktopAcrylicController.AddSystemBackdropTarget(m_Target); // This is where the error is
desktopAcrylicController.SetSystemBackdropConfiguration(m_configurationSource);
}