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">
-
+
+
+
+
+
+
+
+
-
-
-
-
-
+ Spacing="20">
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WinUIGallery/SamplePages/SampleBuiltInSystemBackdropsWindow.xaml.cs b/WinUIGallery/SamplePages/SampleBuiltInSystemBackdropsWindow.xaml.cs
index 61f425cc8..98c077454 100644
--- a/WinUIGallery/SamplePages/SampleBuiltInSystemBackdropsWindow.xaml.cs
+++ b/WinUIGallery/SamplePages/SampleBuiltInSystemBackdropsWindow.xaml.cs
@@ -1,28 +1,35 @@
-using WinUIGallery.Helper;
+using System;
+using Microsoft.UI;
+using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Controls;
+using Microsoft.UI.Xaml.Media;
+using WinUIGallery.DesktopWap.Helper;
+using WinUIGallery.Helper;
namespace WinUIGallery.SamplePages;
public sealed partial class SampleBuiltInSystemBackdropsWindow : Window
{
- BackdropType m_currentBackdrop;
+ BackdropType currentBackdrop;
public SampleBuiltInSystemBackdropsWindow()
{
- this.InitializeComponent();
- ((FrameworkElement)this.Content).RequestedTheme = WinUIGallery.Helper.ThemeHelper.RootTheme;
+ InitializeComponent();
+ AppWindow.SetIcon(@"Assets\Tiles\GalleryIcon.ico");
ExtendsContentIntoTitleBar = true;
- SetTitleBar(titleBar);
- SetBackdrop(BackdropType.Mica);
- }
+ backdropComboBox.SelectedIndex = 0;
+ themeComboBox.SelectedIndex = 0;
+ ((FrameworkElement)Content).RequestedTheme = ThemeHelper.RootTheme;
+ }
public enum BackdropType
{
+ None,
Mica,
MicaAlt,
- DesktopAcrylic,
- DefaultColor,
+ Acrylic
}
public void SetBackdrop(BackdropType type)
@@ -33,48 +40,41 @@ public void SetBackdrop(BackdropType type)
// common pattern of an app simply choosing one controller type which it sets at
// startup. If an app wants to toggle between Mica and Acrylic it could simply
// call RemoveSystemBackdropTarget() on the old controller and then setup the new
- // controller, reusing any existing m_configurationSource and Activated/Closed
+ // controller, reusing any existing configurationSource and Activated/Closed
// event handlers.
- m_currentBackdrop = BackdropType.DefaultColor;
- tbCurrentBackdrop.Text = "None (default theme color)";
+
+ //Reset the backdrop
+ currentBackdrop = BackdropType.None;
tbChangeStatus.Text = "";
- this.SystemBackdrop = null;
+ SystemBackdrop = null;
+ //Set the backdrop
if (type == BackdropType.Mica)
{
if (TrySetMicaBackdrop(false))
- {
- tbCurrentBackdrop.Text = "Built-in Mica";
- m_currentBackdrop = type;
- }
+ currentBackdrop = type;
else
{
// Mica isn't supported. Try Acrylic.
- type = BackdropType.DesktopAcrylic;
+ type = BackdropType.Acrylic;
tbChangeStatus.Text += " Mica isn't supported. Trying Acrylic.";
}
}
if (type == BackdropType.MicaAlt)
{
if (TrySetMicaBackdrop(true))
- {
- tbCurrentBackdrop.Text = "Built-in MicaAlt";
- m_currentBackdrop = type;
- }
+ currentBackdrop = type;
else
{
// MicaAlt isn't supported. Try Acrylic.
- type = BackdropType.DesktopAcrylic;
+ type = BackdropType.Acrylic;
tbChangeStatus.Text += " MicaAlt isn't supported. Trying Acrylic.";
}
}
- if (type == BackdropType.DesktopAcrylic)
+ if (type == BackdropType.Acrylic)
{
if (TrySetAcrylicBackdrop())
- {
- tbCurrentBackdrop.Text = "Built-in Acrylic";
- m_currentBackdrop = type;
- }
+ currentBackdrop = type;
else
{
// Acrylic isn't supported, so take the next option, which is DefaultColor, which is already set.
@@ -82,17 +82,18 @@ public void SetBackdrop(BackdropType type)
}
}
+ //Fix the none backdrop
+ SetNoneBackdropBackground();
+
// Announce visual change to automation.
- UIHelper.AnnounceActionForAccessibility(btnChangeBackdrop, $"Background changed to {tbCurrentBackdrop.Text}", "BackgroundChangedNotificationActivityId");
+ UIHelper.AnnounceActionForAccessibility(backdropComboBox, $"Background changed to {currentBackdrop}", "BackgroundChangedNotificationActivityId");
}
bool TrySetMicaBackdrop(bool useMicaAlt)
{
- if (Microsoft.UI.Composition.SystemBackdrops.MicaController.IsSupported())
+ if (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;
+ SystemBackdrop = new MicaBackdrop { Kind = useMicaAlt ? MicaKind.BaseAlt : MicaKind.Base }; ;
return true;
}
@@ -101,28 +102,40 @@ bool TrySetMicaBackdrop(bool useMicaAlt)
bool TrySetAcrylicBackdrop()
{
- if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.IsSupported())
+ if (DesktopAcrylicController.IsSupported())
{
- this.SystemBackdrop = new Microsoft.UI.Xaml.Media.DesktopAcrylicBackdrop();
+ SystemBackdrop = new DesktopAcrylicBackdrop();
return true;
}
return false; // Acrylic is not supported on this system
}
+
+ private void BackdropComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ SetBackdrop(backdropComboBox.SelectedIndex switch
+ {
+ 1 => BackdropType.MicaAlt,
+ 2 => BackdropType.Acrylic,
+ 3 => BackdropType.None,
+ _ => BackdropType.Mica
+ });
+ }
- void ChangeBackdropButton_Click(object sender, RoutedEventArgs e)
+ private void ThemeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
- BackdropType newType;
+ ((FrameworkElement)Content).RequestedTheme = Enum.GetValues()[themeComboBox.SelectedIndex];
- switch (m_currentBackdrop)
- {
- case BackdropType.Mica: newType = BackdropType.MicaAlt; break;
- case BackdropType.MicaAlt: newType = BackdropType.DesktopAcrylic; break;
- case BackdropType.DesktopAcrylic: newType = BackdropType.DefaultColor; break;
- default:
- case BackdropType.DefaultColor: newType = BackdropType.Mica; break;
- }
+ TitleBarHelper.SetCaptionButtonColors(this, ((FrameworkElement)Content).ActualTheme == ElementTheme.Dark ? Colors.White : Colors.Black);
+ SetNoneBackdropBackground();
+ }
- SetBackdrop(newType);
+ //Fixes the background color not changing when switching between themes.
+ void SetNoneBackdropBackground()
+ {
+ if (currentBackdrop == BackdropType.None && themeComboBox.SelectedIndex != 0)
+ ((Grid)Content).Background = new SolidColorBrush(themeComboBox.SelectedIndex == 1 ? Colors.White : Colors.Black);
+ else
+ ((Grid)Content).Background = new SolidColorBrush(Colors.Transparent);
}
}
diff --git a/WinUIGallery/SamplePages/SampleSystemBackdropsWindow.xaml b/WinUIGallery/SamplePages/SampleSystemBackdropsWindow.xaml
index ffc726505..4b681e36e 100644
--- a/WinUIGallery/SamplePages/SampleSystemBackdropsWindow.xaml
+++ b/WinUIGallery/SamplePages/SampleSystemBackdropsWindow.xaml
@@ -4,29 +4,58 @@
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">
-
+
+
+
+
+
+
+
+
-
-
-
-
-
+ Spacing="20">
+
+
+
+
+
+
+
+
diff --git a/WinUIGallery/SamplePages/SampleSystemBackdropsWindow.xaml.cs b/WinUIGallery/SamplePages/SampleSystemBackdropsWindow.xaml.cs
index a182f93de..2fde7251e 100644
--- a/WinUIGallery/SamplePages/SampleSystemBackdropsWindow.xaml.cs
+++ b/WinUIGallery/SamplePages/SampleSystemBackdropsWindow.xaml.cs
@@ -1,80 +1,53 @@
-using System;
-using System.Runtime.InteropServices; // For DllImport
using WinUIGallery.Helper;
using Microsoft.UI.Xaml;
-using WinRT; // required to support Window.As()
+using WinRT;// required to support Window.As()
+using Microsoft.UI.Composition.SystemBackdrops;
+using Microsoft.UI.Xaml.Media;
+using Microsoft.UI.Xaml.Controls;
+using Microsoft.UI.Windowing;
+using Microsoft.UI;
+using WinUIGallery.DesktopWap.Helper;
+using Microsoft.UI.Composition;
+using System;
namespace WinUIGallery.SamplePages;
-class WindowsSystemDispatcherQueueHelper
+public sealed partial class SampleSystemBackdropsWindow : Window
{
- [StructLayout(LayoutKind.Sequential)]
- struct DispatcherQueueOptions
+ public BackdropType[] AllowedBackdrops
{
- internal int dwSize;
- internal int threadType;
- internal int apartmentType;
+ get => (BackdropType[])backdropComboBox.ItemsSource;
+ set => backdropComboBox.ItemsSource = value;
}
-
- [DllImport("CoreMessaging.dll")]
- private static unsafe extern int CreateDispatcherQueueController(DispatcherQueueOptions options, IntPtr* instance);
-
- IntPtr m_dispatcherQueueController = IntPtr.Zero;
- public void EnsureWindowsSystemDispatcherQueueController()
- {
- if (Windows.System.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;
- }
- }
- }
-}
+ WindowsSystemDispatcherQueueHelper wsdqHelper;
+ BackdropType currentBackdrop;
+ MicaController micaController;
+ DesktopAcrylicController acrylicController;
+ SystemBackdropConfiguration configurationSource;
-public sealed partial class SampleSystemBackdropsWindow : Window
-{
public SampleSystemBackdropsWindow()
{
- this.InitializeComponent();
- ((FrameworkElement)this.Content).RequestedTheme = WinUIGallery.Helper.ThemeHelper.RootTheme;
+ InitializeComponent();
+ AppWindow.SetIcon(@"Assets\Tiles\GalleryIcon.ico");
ExtendsContentIntoTitleBar = true;
- SetTitleBar(titleBar);
- m_wsdqHelper = new WindowsSystemDispatcherQueueHelper();
- m_wsdqHelper.EnsureWindowsSystemDispatcherQueueController();
+ ((FrameworkElement)Content).RequestedTheme = ThemeHelper.RootTheme;
+ wsdqHelper = new WindowsSystemDispatcherQueueHelper();
+ wsdqHelper.EnsureWindowsSystemDispatcherQueueController();
- SetBackdrop(BackdropType.Mica);
+ backdropComboBox.SelectedIndex = 0;
+ themeComboBox.SelectedIndex = 0;
}
-
public enum BackdropType
{
+ None,
Mica,
MicaAlt,
- DesktopAcrylicBase,
- DesktopAcrylicThin,
- DefaultColor,
+ Acrylic,
+ AcrylicThin
}
- WindowsSystemDispatcherQueueHelper m_wsdqHelper;
- BackdropType m_currentBackdrop;
- Microsoft.UI.Composition.SystemBackdrops.MicaController m_micaController;
- Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController m_acrylicController;
- Microsoft.UI.Composition.SystemBackdrops.SystemBackdropConfiguration m_configurationSource;
-
public void SetBackdrop(BackdropType type)
{
// Reset to default color. If the requested type is supported, we'll update to that.
@@ -85,105 +58,88 @@ public void SetBackdrop(BackdropType type)
// call RemoveSystemBackdropTarget() on the old controller and then setup the new
// controller, reusing any existing m_configurationSource and Activated/Closed
// event handlers.
- m_currentBackdrop = BackdropType.DefaultColor;
- tbCurrentBackdrop.Text = "None (default theme color)";
+
+ //Reset the backdrop
+ currentBackdrop = BackdropType.None;
tbChangeStatus.Text = "";
- if (m_micaController != null)
- {
- m_micaController.Dispose();
- m_micaController = null;
- }
- if (m_acrylicController != null)
- {
- m_acrylicController.Dispose();
- m_acrylicController = null;
- }
- this.Activated -= Window_Activated;
- this.Closed -= Window_Closed;
- ((FrameworkElement)this.Content).ActualThemeChanged -= Window_ThemeChanged;
- m_configurationSource = null;
+ micaController?.Dispose();
+ micaController = null;
+ acrylicController?.Dispose();
+ acrylicController = null;
+ configurationSource = null;
+
+ //Set the backdrop
if (type == BackdropType.Mica)
{
if (TrySetMicaBackdrop(false))
- {
- tbCurrentBackdrop.Text = "Custom Mica";
- m_currentBackdrop = type;
- }
+ currentBackdrop = type;
else
{
// Mica isn't supported. Try Acrylic.
- type = BackdropType.DesktopAcrylicBase;
+ type = BackdropType.Acrylic;
tbChangeStatus.Text += " Mica isn't supported. Trying Acrylic.";
}
}
if (type == BackdropType.MicaAlt)
{
if (TrySetMicaBackdrop(true))
- {
- tbCurrentBackdrop.Text = "Custom MicaAlt";
- m_currentBackdrop = type;
- }
+ currentBackdrop = type;
else
{
// MicaAlt isn't supported. Try Acrylic.
- type = BackdropType.DesktopAcrylicBase;
+ type = BackdropType.Acrylic;
tbChangeStatus.Text += " MicaAlt isn't supported. Trying Acrylic.";
}
}
- if (type == BackdropType.DesktopAcrylicBase)
+ if (type == BackdropType.Acrylic)
{
if (TrySetAcrylicBackdrop(false))
- {
- tbCurrentBackdrop.Text = "Custom Acrylic (Base)";
- m_currentBackdrop = type;
- }
+ currentBackdrop = type;
else
{
// Acrylic isn't supported, so take the next option, which is DefaultColor, which is already set.
tbChangeStatus.Text += " Acrylic Base isn't supported. Switching to default color.";
}
}
- if (type == BackdropType.DesktopAcrylicThin)
+ if (type == BackdropType.AcrylicThin)
{
if (TrySetAcrylicBackdrop(true))
- {
- tbCurrentBackdrop.Text = "Custom Acrylic (Thin)";
- m_currentBackdrop = type;
- }
+ currentBackdrop = type;
else
{
// Acrylic isn't supported, so take the next option, which is DefaultColor, which is already set.
tbChangeStatus.Text += " Acrylic Thin isn't supported. Switching to default color.";
}
}
-
- // announce visual change to automation
- UIHelper.AnnounceActionForAccessibility(btnChangeBackdrop, $"Background changed to {tbCurrentBackdrop.Text}", "BackgroundChangedNotificationActivityId");
+
+ //Fix the none backdrop
+ SetNoneBackdropBackground();
+
+ //Announce visual change to automation
+ UIHelper.AnnounceActionForAccessibility(backdropComboBox, $"Background changed to {currentBackdrop}", "BackgroundChangedNotificationActivityId");
}
bool TrySetMicaBackdrop(bool useMicaAlt)
{
- if (Microsoft.UI.Composition.SystemBackdrops.MicaController.IsSupported())
+ if (MicaController.IsSupported())
{
// 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;
+ configurationSource = new SystemBackdropConfiguration();
+ Activated += Window_Activated;
+ Closed += Window_Closed;
+ ((FrameworkElement)Content).ActualThemeChanged += Window_ThemeChanged;
// Initial configuration state.
- m_configurationSource.IsInputActive = true;
+ 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;
+ micaController = new MicaController { Kind = useMicaAlt ? MicaKind.BaseAlt : 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);
+ micaController.AddSystemBackdropTarget(this.As());
+ micaController.SetSystemBackdropConfiguration(configurationSource);
return true; // Succeeded.
}
@@ -192,26 +148,24 @@ bool TrySetMicaBackdrop(bool useMicaAlt)
bool TrySetAcrylicBackdrop(bool useAcrylicThin)
{
- if (Microsoft.UI.Composition.SystemBackdrops.DesktopAcrylicController.IsSupported())
+ if (DesktopAcrylicController.IsSupported())
{
// 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;
+ configurationSource = new SystemBackdropConfiguration();
+ Activated += Window_Activated;
+ Closed += Window_Closed;
+ ((FrameworkElement)Content).ActualThemeChanged += Window_ThemeChanged;
// Initial configuration state.
- m_configurationSource.IsInputActive = true;
+ 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;
+ acrylicController = new DesktopAcrylicController { Kind = useAcrylicThin ? DesktopAcrylicKind.Thin : 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);
+ acrylicController.AddSystemBackdropTarget(this.As());
+ acrylicController.SetSystemBackdropConfiguration(configurationSource);
return true; // Succeeded.
}
@@ -220,57 +174,55 @@ bool TrySetAcrylicBackdrop(bool useAcrylicThin)
private void Window_Activated(object sender, WindowActivatedEventArgs args)
{
- m_configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated;
+ if(configurationSource != null)
+ 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;
- }
- if (m_acrylicController != null)
- {
- m_acrylicController.Dispose();
- m_acrylicController = null;
- }
- this.Activated -= Window_Activated;
- m_configurationSource = null;
+ micaController?.Dispose();
+ micaController = null;
+ acrylicController?.Dispose();
+ acrylicController = null;
+ configurationSource = null;
+
+ Activated -= Window_Activated;
+ Closed -= Window_Closed;
+ ((FrameworkElement)Content).ActualThemeChanged -= Window_ThemeChanged;
}
private void Window_ThemeChanged(FrameworkElement sender, object args)
{
- if (m_configurationSource != null)
- {
+ if (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;
- }
+ configurationSource.Theme = (SystemBackdropTheme)((FrameworkElement)Content).ActualTheme;
}
- void ChangeBackdropButton_Click(object sender, RoutedEventArgs e)
+ private void BackdropComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
- BackdropType newType;
- switch (m_currentBackdrop)
- {
- case BackdropType.Mica: newType = BackdropType.MicaAlt; break;
- case BackdropType.MicaAlt: newType = BackdropType.DesktopAcrylicBase; break;
- case BackdropType.DesktopAcrylicBase: newType = BackdropType.DesktopAcrylicThin; break;
- case BackdropType.DesktopAcrylicThin: newType = BackdropType.DefaultColor; break;
- default:
- case BackdropType.DefaultColor: newType = BackdropType.Mica; break;
- }
- SetBackdrop(newType);
+ SetBackdrop((BackdropType) backdropComboBox.SelectedItem);
+ }
+
+ private void ThemeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ ((FrameworkElement)Content).RequestedTheme = Enum.GetValues()[themeComboBox.SelectedIndex];
+
+ TitleBarHelper.SetCaptionButtonColors(this, ((FrameworkElement)Content).ActualTheme == ElementTheme.Dark ? Colors.White : Colors.Black);
+ SetNoneBackdropBackground();
+ }
+
+ //Fixes the background color not changing when switching between themes.
+ void SetNoneBackdropBackground()
+ {
+ if (currentBackdrop == BackdropType.None && themeComboBox.SelectedIndex != 0)
+ ((Grid)Content).Background = new SolidColorBrush(themeComboBox.SelectedIndex == 1 ? Colors.White : Colors.Black);
+ else
+ ((Grid)Content).Background = new SolidColorBrush(Colors.Transparent);
}
}