bool TrySetMicaBackdrop() { if (Microsoft.UI.Composition.SystemBackdrops.MicaController.IsSupported()) { m_wsdqHelper = new WindowsSystemDispatcherQueueHelper(); m_wsdqHelper.EnsureWindowsSystemDispatcherQueueController(); // Hooking up the policy object m_configurationSource = new Microsoft.UI.Composition.SystemBackdrops.SystemBackdropConfiguration(); this.Activated += Window_Activated; this.Closed += Window_Closed; // Initial configuration state. m_configurationSource.IsInputActive = true; switch (((FrameworkElement)this.Content).ActualTheme) { case ElementTheme.Dark: m_configurationSource.Theme = Microsoft.UI.Composition.SystemBackdrops.SystemBackdropTheme.Dark; break; case ElementTheme.Light: m_configurationSource.Theme = Microsoft.UI.Composition.SystemBackdrops.SystemBackdropTheme.Light; break; case ElementTheme.Default: m_configurationSource.Theme = Microsoft.UI.Composition.SystemBackdrops.SystemBackdropTheme.Default; break; } m_micaController = new Microsoft.UI.Composition.SystemBackdrops.MicaController(); // Enable the system backdrop. // Note: Be sure to have "using WinRT;" to support the Window.As<...>() call. m_micaController.AddSystemBackdropTarget(this.As <Microsoft.UI.Composition.ICompositionSupportsSystemBackdrop>()); m_micaController.SetSystemBackdropConfiguration(m_configurationSource); return(true); // succeeded } return(false); // Mica is not supported on this system }
private void Window_Closed(object sender, WindowEventArgs args) { // Make sure any Mica/Acrylic controller is disposed so it doesn't try to // use this closed window. if (m_micaController != null) { m_micaController.Dispose(); m_micaController = null; } this.Activated -= Window_Activated; m_configurationSource = null; }