diff --git a/WinUIGallery/ContentIncludes.props b/WinUIGallery/ContentIncludes.props index ae325a930..ccc324f5e 100644 --- a/WinUIGallery/ContentIncludes.props +++ b/WinUIGallery/ContentIncludes.props @@ -245,10 +245,10 @@ - - - - + + + + diff --git a/WinUIGallery/ControlPages/SystemBackdropsPage.xaml b/WinUIGallery/ControlPages/SystemBackdropsPage.xaml index d95b7bc01..b08c74ec9 100644 --- a/WinUIGallery/ControlPages/SystemBackdropsPage.xaml +++ b/WinUIGallery/ControlPages/SystemBackdropsPage.xaml @@ -19,45 +19,62 @@ mc:Ignorable="d"> - - - -// Option 1 - implement Mica with Xaml. -<Window.SystemBackdrop> - <MicaBackdrop /> -</Window.SystemBackdrop> - - - - - - - + + + + There are three backdrop types: + 1. SystemBackdrop (The base class of every backdrop type) + 2. MicaBackdrop (A backdrop that uses the Mica material) + 3. DesktopAcrylicBackdrop (A backdrop that uses the Acrylic material) + + Mica is an opaque, dynamic material that incorporates theme and desktop wallpaper to paint the background of windows. + Mica is specifically designed for app performance as it only samples the desktop wallpaper once to create its visualization. + Mica Alt is a variant of Mica, with stronger tinting of the user's desktop background. Recommended when creating an app with a tabbed title bar. + All variants of Mica are available for Windows 11 build 22000 or later. + + Acrylic is a semi-transparent material that replicates the effect of frosted glass. It's used only for transient, light-dismiss surfaces such as flyouts and context menus. + There are two acrylic blend types that change what's visible through the material: + + Background acrylic reveals the desktop wallpaper and other windows that are behind the currently active app, adding depth between application windows while celebrating the user's personalization preferences. + In-app acrylic adds a sense of depth within the app frame, providing both focus and hierarchy. (Inplemented with a AcrylicBrush in XAML) + + + - - - -// Option 1 - implement Acrylic with Xaml. -<Window.SystemBackdrop> - <DesktopAcrylicBackdrop /> -</Window.SystemBackdrop> - - - + + + + Manages rendering and system policy for the mica material. The MicaController class provides a very customizable way to apply the Mica material to an app. + This is a list of properties that can be modified: FallbackColor, Kind, LuminosityOpacity, TintColor and the TintOpacity. + There are 2 types of Mica: + 1. Base (Lighter) + 2. Alt (Darker) + + + - - + + + + Manages rendering and system policy for the background acrylic material. Acrylic has the same level of customization as Mica, but the type can't be changed using the DesktopAcrylicBackdrop class. + There are 2 types of Acrylic: + 1. Base (Darker) + 2. Thin (Lighter) + If you wan't to use Acrylic Thin in your app you have to use the DesktopAcrylicController class. The DesktopAcrylicBackdrop class uses the Base type. + + + - - + diff --git a/WinUIGallery/ControlPages/SystemBackdropsPage.xaml.cs b/WinUIGallery/ControlPages/SystemBackdropsPage.xaml.cs index 2b2ab6b80..e7cfdcf2b 100644 --- a/WinUIGallery/ControlPages/SystemBackdropsPage.xaml.cs +++ b/WinUIGallery/ControlPages/SystemBackdropsPage.xaml.cs @@ -7,13 +7,9 @@ // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. // //********************************************************* -using WinUIGallery.Helper; -using System; -using Microsoft.UI; -using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Media; +using WinUIGallery.SamplePages; namespace WinUIGallery.ControlPages; @@ -21,33 +17,39 @@ public sealed partial class SystemBackdropsPage : Page { public SystemBackdropsPage() { - this.InitializeComponent(); + InitializeComponent(); } - private void createBuiltInMicaWindow_Click(object sender, RoutedEventArgs e) + private void createBuiltInWindow_Click(object sender, RoutedEventArgs e) { - var newWindow = new WinUIGallery.SamplePages.SampleBuiltInSystemBackdropsWindow(); - newWindow.Activate(); + var buildInBackdropsWindow = new SampleBuiltInSystemBackdropsWindow(); + buildInBackdropsWindow.SetBackdrop(SampleBuiltInSystemBackdropsWindow.BackdropType.Mica); + buildInBackdropsWindow.Activate(); } private void createCustomMicaWindow_Click(object sender, RoutedEventArgs e) { - var newWindow = new WinUIGallery.SamplePages.SampleSystemBackdropsWindow(); - newWindow.SetBackdrop(WinUIGallery.SamplePages.SampleSystemBackdropsWindow.BackdropType.Mica); - newWindow.Activate(); - } - - private void createBuiltInAcrylicWindow_Click(object sender, RoutedEventArgs e) - { - var newWindow = new WinUIGallery.SamplePages.SampleSystemBackdropsWindow(); - newWindow.SetBackdrop(WinUIGallery.SamplePages.SampleSystemBackdropsWindow.BackdropType.DesktopAcrylicBase); - newWindow.Activate(); + var micaWindow = new SampleSystemBackdropsWindow + { + AllowedBackdrops = [ + SampleSystemBackdropsWindow.BackdropType.Mica, + SampleSystemBackdropsWindow.BackdropType.MicaAlt, + SampleSystemBackdropsWindow.BackdropType.None + ] + }; + micaWindow.Activate(); } private void createCustomDesktopAcrylicWindow_Click(object sender, RoutedEventArgs e) { - var newWindow = new WinUIGallery.SamplePages.SampleSystemBackdropsWindow(); - newWindow.SetBackdrop(WinUIGallery.SamplePages.SampleSystemBackdropsWindow.BackdropType.DesktopAcrylicBase); - newWindow.Activate(); + var acrylicWindow = new SampleSystemBackdropsWindow + { + AllowedBackdrops = [ + SampleSystemBackdropsWindow.BackdropType.Acrylic, + SampleSystemBackdropsWindow.BackdropType.AcrylicThin, + SampleSystemBackdropsWindow.BackdropType.None + ] + }; + acrylicWindow.Activate(); } } diff --git a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample1.txt b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample1.txt deleted file mode 100644 index 5606bd3b5..000000000 --- a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample1.txt +++ /dev/null @@ -1,73 +0,0 @@ -using System.Runtime.InteropServices; // For DllImport -using WinRT; // required to support Window.As() - -WindowsSystemDispatcherQueueHelper m_wsdqHelper; // See separate sample below for implementation -Microsoft.UI.Composition.SystemBackdrops.MicaController m_micaController; -Microsoft.UI.Composition.SystemBackdrops.SystemBackdropConfiguration m_configurationSource; - -bool TrySetMicaBackdrop(bool useMicaAlt) -{ - 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; - ((FrameworkElement)this.Content).ActualThemeChanged += Window_ThemeChanged; - - // Initial configuration state. - m_configurationSource.IsInputActive = true; - SetConfigurationSourceTheme(); - - m_micaController = new Microsoft.UI.Composition.SystemBackdrops.MicaController(); - - m_micaController.Kind = useMicaAlt ? Microsoft.UI.Composition.SystemBackdrops.MicaKind.BaseAlt : Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base; - - // Enable the system backdrop. - // Note: Be sure to have "using WinRT;" to support the Window.As<...>() call. - m_micaController.AddSystemBackdropTarget(this.As()); - m_micaController.SetSystemBackdropConfiguration(m_configurationSource); - return true; // Succeeded. - } - - return false; // Mica is not supported on this system. -} - -private void Window_Activated(object sender, WindowActivatedEventArgs args) -{ - m_configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated; -} - -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; -} - -private void Window_ThemeChanged(FrameworkElement sender, object args) -{ - if (m_configurationSource != null) - { - SetConfigurationSourceTheme(); - } -} - -private void SetConfigurationSourceTheme() -{ - 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; - } -} diff --git a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample2.txt b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample2.txt deleted file mode 100644 index f47c55ac2..000000000 --- a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample2.txt +++ /dev/null @@ -1,73 +0,0 @@ -using System.Runtime.InteropServices; // For DllImport -using WinRT; // required to support Window.As() - -WindowsSystemDispatcherQueueHelper m_wsdqHelper; // See separate sample below for implementation -Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController m_acrylicController; -Microsoft.UI.Composition.SystemBackdrops.SystemBackdropConfiguration m_configurationSource; - -bool TrySetAcrylicBackdrop(bool useAcrylicThin) -{ - if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.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; - ((FrameworkElement)this.Content).ActualThemeChanged += Window_ThemeChanged; - - // Initial configuration state. - m_configurationSource.IsInputActive = true; - SetConfigurationSourceTheme(); - - m_acrylicController = new Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController(); - - m_acrylicController.Kind = useAcrylicThin ? Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Thin : Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicKind.Base; - - // Enable the system backdrop. - // Note: Be sure to have "using WinRT;" to support the Window.As<...>() call. - m_acrylicController.AddSystemBackdropTarget(this.As()); - m_acrylicController.SetSystemBackdropConfiguration(m_configurationSource); - return true; // Succeeded. - } - - return false; // Acrylic is not supported on this system. -} - -private void Window_Activated(object sender, WindowActivatedEventArgs args) -{ - m_configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated; -} - -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_acrylicController != null) - { - m_acrylicController.Dispose(); - m_acrylicController = null; - } - this.Activated -= Window_Activated; - m_configurationSource = null; -} - -private void Window_ThemeChanged(FrameworkElement sender, object args) -{ - if (m_configurationSource != null) - { - SetConfigurationSourceTheme(); - } -} - -private void SetConfigurationSourceTheme() -{ - 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; - } -} diff --git a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample3.txt b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample3.txt deleted file mode 100644 index ccfa98a90..000000000 --- a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample3.txt +++ /dev/null @@ -1,15 +0,0 @@ -// Option 2 - Implement Mica with codebehind. -// Allows for toggling backdrops as shown in sample. -bool TrySetMicaBackdrop(bool useMicaAlt) -{ - if (Microsoft.UI.Composition.SystemBackdrops.MicaController.IsSupported()) - { - Microsoft.UI.Xaml.Media.MicaBackdrop micaBackdrop = new Microsoft.UI.Xaml.Media.MicaBackdrop(); - micaBackdrop.Kind = useMicaAlt ? Microsoft.UI.Composition.SystemBackdrops.MicaKind.BaseAlt : Microsoft.UI.Composition.SystemBackdrops.MicaKind.Base; - this.SystemBackdrop = micaBackdrop; - - return true; // Succeeded. - } - - return false; // Mica is not supported on this system. -} \ No newline at end of file diff --git a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample4.txt b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample4.txt deleted file mode 100644 index 2b1d40d9b..000000000 --- a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSample4.txt +++ /dev/null @@ -1,14 +0,0 @@ -// Option 2 - Implement Acrylic with codebehind. -// Allows for toggling backdrops as shown in sample. -bool TrySetDesktopAcrylicBackdrop() -{ - if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.IsSupported()) - { - Microsoft.UI.Xaml.Media.DesktopAcrylicBackdrop DesktopAcrylicBackdrop = new Microsoft.UI.Xaml.Media.DesktopAcrylicBackdrop(); - this.SystemBackdrop = DesktopAcrylicBackdrop; - - return true; // Succeeded. - } - - return false; // DesktopAcrylic is not supported on this system. -} \ No newline at end of file diff --git a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleBackdropTypes_cs.txt b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleBackdropTypes_cs.txt new file mode 100644 index 000000000..f5fe1b8ce --- /dev/null +++ b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleBackdropTypes_cs.txt @@ -0,0 +1,26 @@ +bool TrySetMicaBackdrop(bool useMicaAlt) +{ + if (SystemBackdrops.MicaController.IsSupported()) + { + MicaBackdrop micaBackdrop = new MicaBackdrop(); + micaBackdrop.Kind = useMicaAlt ? MicaKind.BaseAlt : MicaKind.Base; + SystemBackdrop = micaBackdrop; + + return true; // Succeeded. + } + + return false; // Mica is not supported on this system. +} + +bool TrySetDesktopAcrylicBackdrop() +{ + if (DesktopAcrylicController.IsSupported()) + { + DesktopAcrylicBackdrop DesktopAcrylicBackdrop = new DesktopAcrylicBackdrop(); + SystemBackdrop = DesktopAcrylicBackdrop; + + return true; // Succeeded. + } + + return false; // DesktopAcrylic is not supported on this system. +} \ No newline at end of file diff --git a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleBackdropTypes_xaml.txt b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleBackdropTypes_xaml.txt new file mode 100644 index 000000000..98ac5ce23 --- /dev/null +++ b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleBackdropTypes_xaml.txt @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleDesktopAcrylicController.txt b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleDesktopAcrylicController.txt new file mode 100644 index 000000000..34622844e --- /dev/null +++ b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleDesktopAcrylicController.txt @@ -0,0 +1,72 @@ +using System.Runtime.InteropServices; +using WinRT; +using Microsoft.UI.Composition; +using Microsoft.UI.Composition.SystemBackdrops; + +WindowsSystemDispatcherQueueHelper wsdqHelper; // See the helper class sample for the implementation +SystemBackdrops.DesktopAcrylicController acrylicController; +SystemBackdrops.SystemBackdropConfiguration configurationSource; + +bool TrySetAcrylicBackdrop(bool useAcrylicThin) +{ + if (DesktopAcrylicController.IsSupported()) + { + wsdqHelper = new WindowsSystemDispatcherQueueHelper(); + wsdqHelper.EnsureWindowsSystemDispatcherQueueController(); + + // Hooking up the policy object + configurationSource = new SystemBackdropConfiguration(); + Activated += Window_Activated; + Closed += Window_Closed; + ((FrameworkElement)Content).ActualThemeChanged += Window_ThemeChanged; + + // Initial configuration state. + configurationSource.IsInputActive = true; + SetConfigurationSourceTheme(); + + acrylicController = new DesktopAcrylicController(); + acrylicController.Kind = useAcrylicThin ? DesktopAcrylicKind.Thin : DesktopAcrylicKind.Base; + + // Enable the system backdrop. + acrylicController.AddSystemBackdropTarget(As()); + acrylicController.SetSystemBackdropConfiguration(configurationSource); + return true; // Succeeded. + } + + return false; // Acrylic is not supported on this system. +} + +private void Window_Activated(object sender, WindowActivatedEventArgs args) +{ + configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated; +} + +private void Window_Closed(object sender, WindowEventArgs args) +{ + // Make sure any Mica/Acrylic controller is disposed + if (acrylicController != null) + { + acrylicController.Dispose(); + acrylicController = null; + } + Activated -= Window_Activated; + configurationSource = null; +} + +private void Window_ThemeChanged(FrameworkElement sender, object args) +{ + if (configurationSource != null) + { + SetConfigurationSourceTheme(); + } +} + +private void SetConfigurationSourceTheme() +{ + switch (((FrameworkElement)this.Content).ActualTheme) + { + case ElementTheme.Dark: configurationSource.Theme = SystemBackdropTheme.Dark; break; + case ElementTheme.Light: configurationSource.Theme = SystemBackdropTheme.Light; break; + case ElementTheme.Default: configurationSource.Theme = SystemBackdropTheme.Default; break; + } +} diff --git a/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleMicaController.txt b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleMicaController.txt new file mode 100644 index 000000000..f9f4aa60c --- /dev/null +++ b/WinUIGallery/ControlPagesSampleCode/SystemBackdrops/SystemBackdropsSampleMicaController.txt @@ -0,0 +1,72 @@ +using System.Runtime.InteropServices; +using WinRT; +using Microsoft.UI.Composition; +using Microsoft.UI.Composition.SystemBackdrops; + +WindowsSystemDispatcherQueueHelper wsdqHelper; // See the helper class sample for the implementation +MicaController micaController; +SystemBackdropConfiguration configurationSource; + +bool TrySetMicaBackdrop(bool useMicaAlt) +{ + if (MicaController.IsSupported()) + { + wsdqHelper = new WindowsSystemDispatcherQueueHelper(); + wsdqHelper.EnsureWindowsSystemDispatcherQueueController(); + + // Hooking up the policy object + configurationSource = new SystemBackdropConfiguration(); + Activated += Window_Activated; + Closed += Window_Closed; + ((FrameworkElement)Content).ActualThemeChanged += Window_ThemeChanged; + + // Initial configuration state. + configurationSource.IsInputActive = true; + SetConfigurationSourceTheme(); + + micaController = new MicaController(); + micaController.Kind = useMicaAlt ? MicaKind.BaseAlt : MicaKind.Base; + + // Enable the system backdrop. + micaController.AddSystemBackdropTarget(this.As()); + micaController.SetSystemBackdropConfiguration(configurationSource); + return true; // Succeeded. + } + + return false; // Mica is not supported on this system. +} + +private void Window_Activated(object sender, WindowActivatedEventArgs args) +{ + configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated; +} + +private void Window_Closed(object sender, WindowEventArgs args) +{ + // Make sure any Mica/Acrylic controller is disposed + if (micaController != null) + { + micaController.Dispose(); + micaController = null; + } + this.Activated -= Window_Activated; + configurationSource = null; +} + +private void Window_ThemeChanged(FrameworkElement sender, object args) +{ + if (configurationSource != null) + { + SetConfigurationSourceTheme(); + } +} + +private void SetConfigurationSourceTheme() +{ + switch (((FrameworkElement)Content).ActualTheme) + { + case ElementTheme.Dark: configurationSource.Theme = SystemBackdropTheme.Dark; break; + case ElementTheme.Light: configurationSource.Theme = SystemBackdropTheme.Light; break; + case ElementTheme.Default: configurationSource.Theme = SystemBackdropTheme.Default; break; + } +} diff --git a/WinUIGallery/DataModel/ControlInfoData.json b/WinUIGallery/DataModel/ControlInfoData.json index 13455c9ca..a738cfa56 100644 --- a/WinUIGallery/DataModel/ControlInfoData.json +++ b/WinUIGallery/DataModel/ControlInfoData.json @@ -2928,10 +2928,27 @@ "ApiNamespace": "Microsoft.UI.Composition.SystemBackdrops", "Subtitle": "System backdrops, like Mica and Acrylic, for the window.", "ImagePath": "ms-appx:///Assets/ControlImages/Acrylic.png", - "Description": "System backdrops are used to provide a different background for a Window other than the default white or black (depending on Light or Dark theme). Mica and Desktop Acrylic are the current supported backdrops. There are two options for applying a backdrop: first, to use built-in Mica/Acrylic types, which have no customization and are simple to apply. The second is to create a customizable backdrop, which requires more code.", + "Description": "System backdrops provide a transparency effect for the window background. Mica and Acrylic are the current supported backdrops. There are two options for applying a backdrop: first, to use built-in Mica/Acrylic types, which have no customization and are simple to apply. The second is to create a customizable backdrop, which requires more code.", "Content": "

Look at the SampleSystemBackdropsWindow.xaml.cs file in Visual Studio to see the full code for applying a backdrop.

", "SourcePath": "/Materials", + "IsUpdated": true, + "BaseClasses": [ + "Object", + "DependencyObject" + ], "Docs": [ + { + "Title": "SystemBackdrop - API", + "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.systembackdrop" + }, + { + "Title": "MicaBackdrop - API", + "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.micabackdrop" + }, + { + "Title": "DesktopAcrylicBackdrop - API", + "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.desktopacrylicbackdrop" + }, { "Title": "MicaController - API", "Uri": "https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.micacontroller" @@ -2942,6 +2959,7 @@ } ], "RelatedControls": [ + "AcrylicBrush" ] } ] diff --git a/WinUIGallery/Helper/WindowsSystemDispatcherQueueHelper.cs b/WinUIGallery/Helper/WindowsSystemDispatcherQueueHelper.cs new file mode 100644 index 000000000..081f8e8cc --- /dev/null +++ b/WinUIGallery/Helper/WindowsSystemDispatcherQueueHelper.cs @@ -0,0 +1,45 @@ +using System; +using System.Runtime.InteropServices; +using Windows.System; + +namespace WinUIGallery.Helper +{ + class WindowsSystemDispatcherQueueHelper + { + [StructLayout(LayoutKind.Sequential)] + struct DispatcherQueueOptions + { + internal int dwSize; + internal int threadType; + internal int apartmentType; + } + + [DllImport("CoreMessaging.dll")] + private static unsafe extern int CreateDispatcherQueueController(DispatcherQueueOptions options, IntPtr* instance); + + IntPtr m_dispatcherQueueController = IntPtr.Zero; + public void EnsureWindowsSystemDispatcherQueueController() + { + if (DispatcherQueue.GetForCurrentThread() != null) + { + // one already exists, so we'll just use it. + return; + } + + if (m_dispatcherQueueController == IntPtr.Zero) + { + DispatcherQueueOptions options; + options.dwSize = Marshal.SizeOf(typeof(DispatcherQueueOptions)); + options.threadType = 2; // DQTYPE_THREAD_CURRENT + options.apartmentType = 2; // DQTAT_COM_STA + + unsafe + { + IntPtr dispatcherQueueController; + CreateDispatcherQueueController(options, &dispatcherQueueController); + m_dispatcherQueueController = dispatcherQueueController; + } + } + } + } +} diff --git a/WinUIGallery/SamplePages/SampleBuiltInSystemBackdropsWindow.xaml b/WinUIGallery/SamplePages/SampleBuiltInSystemBackdropsWindow.xaml index 78817cdf2..123d8851d 100644 --- a/WinUIGallery/SamplePages/SampleBuiltInSystemBackdropsWindow.xaml +++ b/WinUIGallery/SamplePages/SampleBuiltInSystemBackdropsWindow.xaml @@ -4,29 +4,60 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d"> + mc:Ignorable="d" + Title="SystemBackdrop sample window"> - + + + + + + + + - - - - -