You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: specs/SystemBackdropElement_Spec.md
+17-17Lines changed: 17 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,25 +4,25 @@ SystemBackdropElement
4
4
# Background
5
5
6
6
There are backdrop materials provided in WinUI such as Mica, Acrylic that are subclass of
7
-
[Microsoft.UI.Xaml.Media.SystemBackdrop](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.systembackdrop). Currently, it is possible to add a system backdrop only at the window level or on flyouts, but not in a specific area in the visual tree. This has been a major limitation on WinUI 3 compared to WinUI2 in achieving the acrylic / mica effects, especially for achieving various animations.
7
+
[Microsoft.UI.Xaml.Media.SystemBackdrop](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.systembackdrop). Currently, it is possible to add a system backdrop only at the window level or on flyouts, but not in a specific area in the visual tree. This has been a major limitation on WinUI 3 compared to WinUI 2 in achieving the acrylic / mica effects, especially for achieving various animations.
8
8
9
9
`SystemBackdropElement` is a lightweight `FrameworkElement` that bridges between the XAML tree and the composition
10
10
infrastructure required by `SystemBackdrop`. It creates the required composition components to add the systembackdrop on a specific area, resizes the systembackdrop to fill the given area, and applies the clip on the backdrop visual based on `CornerRadius` values applied on `SystemBackdropElement` which helps for rounded corners to
11
11
appear as expected. This control abstracts lot of details for the composition layer and hence make it easy
12
12
for WinUI 3 developers to implement the acrylic effect in the applications.
13
13
14
-
In WinUI2, it was possible to achieve the backdrop using `BackgroundSource` property of [AcrylicBrush](https://learn.microsoft.com/uwp/api/windows.ui.xaml.media.acrylicbrush?view=winrt-26100), However in WinUI 3, [AcrylicBrush](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.acrylicbrush) doesn't provide `BackgroundSource` property leaving it capable of achieving only in-app acrylic. This is due to the limitation of WinUI 3 compositor which is running in-proc, and so can't fetch buffers outside the application window. In this design, the solution is to leverage the [ContentExternalBackdropLink](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.content.contentexternalbackdroplink) API. It provides `PlacementVisual` that would be used for rendering the backdrop in the WinUI 3 visual tree. `SystemBackdropElement` control takes care of resizing and positioning this `PlacementVisual` as per the position, size and Z-order of the control.
14
+
In WinUI 2, it was possible to achieve the backdrop using `BackgroundSource` property of [AcrylicBrush](https://learn.microsoft.com/uwp/api/windows.ui.xaml.media.acrylicbrush?view=winrt-26100), However in WinUI 3, [AcrylicBrush](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.acrylicbrush) doesn't provide `BackgroundSource` property leaving it capable of achieving only in-app acrylic. This is due to the limitation of WinUI 3 compositor which is running in-proc, and so can't fetch buffers outside the application window. In this design, the solution is to leverage the [ContentExternalBackdropLink](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.content.contentexternalbackdroplink) API. It provides `PlacementVisual` that would be used for rendering the backdrop in the WinUI 3 visual tree. `SystemBackdropElement` control takes care of resizing and positioning this `PlacementVisual` as per the position, size and Z-order of the control.
15
15
16
16
## Goals
17
17
18
-
* Provide an intuitive, XAML-friendly way to place a system backdrop anywhere inside application's visual tree.
19
-
* Handle connection, disconnection, and sizing so application only have to set a backdrop and position the element.
20
-
* Allow to put rounded corners on the backdrop without writing custom composition code.
18
+
- Provide an intuitive, XAML-friendly way to place a system backdrop anywhere inside application's visual tree.
19
+
- Handle connection, disconnection, and sizing so application only have to set a backdrop and position the element.
20
+
- Allow to put rounded corners on the backdrop without writing custom composition code.
21
21
22
22
## Non-goals
23
23
24
-
* Adding a SystemBackdrop property independently on all controls.
25
-
* Provide a content container; `SystemBackdropElement` is purely a visual effect surface and is not a container.
24
+
- Adding a SystemBackdrop property independently on all controls.
25
+
- Provide a content container; `SystemBackdropElement` is purely a visual effect surface and is not a container.
26
26
27
27
# Conceptual pages (How To)
28
28
@@ -76,7 +76,7 @@ Keep the `SystemBackdropElement` in the bottom of the stack below other contents
76
76
77
77
Thesamepatternworksfromcode:
78
78
79
-
*C#:
79
+
-C#:
80
80
81
81
```csharp
82
82
varbackdropElement = newSystemBackdropElement
@@ -87,7 +87,7 @@ var backdropElement = new SystemBackdropElement
@@ -101,27 +101,27 @@ If a `CornerRadius` is applied on the parent `rootGrid`, that would clip the `Sy
101
101
102
102
### Remarks
103
103
104
-
* _Spec note: This API is currently `experimental`; the API surface may still change before it is finalized._
105
-
* It is recommended to be used as first element for background effect to work appropriately, for example as the first child inside a
104
+
- _Spec note: This API is currently `experimental`; the API surface may still change before it is finalized._
105
+
- It is recommended to be used as first element for background effect to work appropriately, for example as the first child inside a
106
106
panel. (First element added to tree gets rendered first and goes in the bottom of stack)
107
-
* The `SystemBackdropElement` only connects to a backdrop while it has a `XamlRoot`. If the element is not in the live tree, the backdrop
107
+
- The `SystemBackdropElement` only connects to a backdrop while it has a `XamlRoot`. If the element is not in the live tree, the backdrop
108
108
remains disconnected until it is loaded.
109
-
* As `SystemBackdropElement` control punches a hole in the layout to show the SystemBackdrop, properties like Shadow, Lights, Clip & Transform may not behave as intended.
109
+
- As `SystemBackdropElement` control punches a hole in the layout to show the SystemBackdrop, properties like Shadow, Lights, Clip & Transform may not behave as intended.
110
110
111
111
## SystemBackdropElement.SystemBackdrop property
112
112
113
113
Gets or sets the `SystemBackdrop` instance that renders in the `SystemBackdropElement` area. The default value is `null`.
114
114
115
-
* You can data bind this property. Typical values include `MicaBackdrop`, `DesktopAcrylicBackdrop`, or a
115
+
- You can data bind this property. Typical values include `MicaBackdrop`, `DesktopAcrylicBackdrop`, or a
116
116
custom subclass of `SystemBackdrop`.
117
-
* If the `SystemBackdropElement` does not yet have a `XamlRoot`, the connection is postponed until one becomes available.
117
+
- If the `SystemBackdropElement` does not yet have a `XamlRoot`, the connection is postponed until one becomes available.
118
118
119
119
## SystemBackdropElement.CornerRadius property
120
120
121
121
Gets or sets the `CornerRadius` applied to the backdrop surface. The default value of `CornerRadius` is 0.
122
122
123
-
* The `SystemBackdropElement` applies a `RectangleClip` on the composition visual of SystemBackdrop to achieve the rounded corners.
124
-
* Default `CornerRadius` value will be 0 aligning with [control templates](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.control.cornerradius#remarks) behavior.
123
+
- The `SystemBackdropElement` applies a `RectangleClip` on the composition visual of SystemBackdrop to achieve the rounded corners.
124
+
- Default `CornerRadius` value will be 0 aligning with [control templates](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.control.cornerradius#remarks) behavior.
or [FlyoutBase](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/Microsoft.UI.Xaml.Controls.Primitives.FlyoutBase)\* (such as a `Flyout` or `MenuFlyout`).
82
82
83
-
*`Popup`/`MenuFlyout``SystemBackdrop` support is not available in WinAppSDK 1.3.0, but is expected to light up in a subsequent release. Note also `SystemBackdrop` will only work in "windowed" popups, i.e. those with _ShouldConstrainToRootBounds=False_.
83
+
-`Popup`/`MenuFlyout``SystemBackdrop` support is not available in WinAppSDK 1.3.0, but is expected to light up in a subsequent release. Note also `SystemBackdrop` will only work in "windowed" popups, i.e. those with _ShouldConstrainToRootBounds=False_.
84
84
85
85
For example:
86
86
@@ -103,8 +103,8 @@ You don't create this class directly, but subclass it to add your custom support
103
103
104
104
Generally, the custom material overrides `OnTargetConnected` to create and configure a backing [ISystemBackdropController](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.isystembackdropcontroller?view=windows-app-sdk-1.3), which will manage the [CompositionBrush](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionbrush?view=windows-app-sdk-1.3) used to fill the backdrop region. The brush's ultimate pixel rendering is affected by the environment/policy (set via [SystemBackdropConfiguration](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.systembackdropconfiguration?view=windows-app-sdk-1.3)) and material's appearance parameters, exposed via general (eg `ICompositionControllerWithTargets.SystemBackdropState` ∈ { _`Active` / `Fallback` / `HighContast`_ }) and material-specfic (eg `MicaController.Kind` ∈ { _`Base` / `BaseAlt`_} _SystemBackdropController_ properties.
105
105
106
-
* The controllers available today (`MicaController` and `DesktopAcrylicController`) support the following parameters for customizing their appearance: [FallbackColor](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.desktopacryliccontroller.fallbackcolor?view=windows-app-sdk-1.3), [LuminosityOpacity](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.desktopacryliccontroller.luminosityopacity?view=windows-app-sdk-1.3), [TintColor](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.micacontroller.tintcolor?view=windows-app-sdk-1.3), and [TintOpacity](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.micacontroller.tintopacity?view=windows-app-sdk-1.3).
107
-
* The provided XAML backdrop materials `MicaBackdrop` and `DesktopAcrylicBackdrop` currently do not expose `FallbackColor` or the material customization properties (`TintOpacity`, etc), instead relying on the default Light/Dark configurations of the underlying `MicaController` and `DesktopAcrylicController`. To customize these properties, createa a custom material class deriving from SystemBackdrop that exposes the desired properties.
106
+
- The controllers available today (`MicaController` and `DesktopAcrylicController`) support the following parameters for customizing their appearance: [FallbackColor](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.desktopacryliccontroller.fallbackcolor?view=windows-app-sdk-1.3), [LuminosityOpacity](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.desktopacryliccontroller.luminosityopacity?view=windows-app-sdk-1.3), [TintColor](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.micacontroller.tintcolor?view=windows-app-sdk-1.3), and [TintOpacity](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.micacontroller.tintopacity?view=windows-app-sdk-1.3).
107
+
- The provided XAML backdrop materials `MicaBackdrop` and `DesktopAcrylicBackdrop` currently do not expose `FallbackColor` or the material customization properties (`TintOpacity`, etc), instead relying on the default Light/Dark configurations of the underlying `MicaController` and `DesktopAcrylicController`. To customize these properties, createa a custom material class deriving from SystemBackdrop that exposes the desired properties.
108
108
109
109
The following example shows a simple custom system backdrop class that's implemented using
@@ -166,18 +166,18 @@ object that is set and maintained automatically for each `SystemBackdrop` usage
166
166
167
167
The properties on `SystemBackdropConfiguration` you receive may change over time:
168
168
169
-
*`Theme`: set based on [ElementTheme](https://learn.microsoft.com/uwp/api/Windows.UI.Xaml.ElementTheme) of the target element (obtained from xamlRoot.Content)
170
-
* If `FallbackColor`, `LuminosityOpacity`, `TintColor`, or `TintOpacity` are modified by the material's implementation, changes to associated [SystemBackdropConfiguration.Theme](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.systembackdropconfiguration.theme?view=windows-app-sdk-1.3) will no longer automatically toggle the controller's theme (since default Dark and Light configurations are no longer appropriate). In this case, the material's appearance properties need to be manually updated to match the new Theme in `SystemBackdrop.OnDefaultSystemBackdropConfigurationChanged`.
169
+
-`Theme`: set based on [ElementTheme](https://learn.microsoft.com/uwp/api/Windows.UI.Xaml.ElementTheme) of the target element (obtained from xamlRoot.Content)
170
+
- If `FallbackColor`, `LuminosityOpacity`, `TintColor`, or `TintOpacity` are modified by the material's implementation, changes to associated [SystemBackdropConfiguration.Theme](https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.systembackdropconfiguration.theme?view=windows-app-sdk-1.3) will no longer automatically toggle the controller's theme (since default Dark and Light configurations are no longer appropriate). In this case, the material's appearance properties need to be manually updated to match the new Theme in `SystemBackdrop.OnDefaultSystemBackdropConfigurationChanged`.
171
171
172
-
*`IsInputActive`: true if the target of the `SystemBackdrop` is in the active window.
172
+
-`IsInputActive`: true if the target of the `SystemBackdrop` is in the active window.
173
173
174
-
*`IsHighContrast`: true if the target of the `SystemBackdrop` is in high contrast mode.
174
+
-`IsHighContrast`: true if the target of the `SystemBackdrop` is in high contrast mode.
Override this method to be called when one of the properties (described above) on the object returned by `GetDefaultSystemBackdropConfiguration` has changed.
179
179
180
-
* This is useful when implementing a custom `SystemBackdropConfiguration` that incorporates some of the tracked property states but is different in some way from the default policy. First, obtain a `SystemBackdropConfiguration` object from `GetDefaultSystemBackdropConfiguration` as usual, but do not apply it via `CompositionController.SetSystemBackdropConfiguration`. Instead create an additional `SystemBackdropConfiguration` object that is updated on `OnDefaultSystemBackdropConfigurationChanged` by applying custom logic to the tracked property (eg ignoring Theme change). The second `SystemBackdropConfiguration` object is hooked up to `CompositionController.SetSystemBackdropConfiguration`, applying the custom policy.
180
+
- This is useful when implementing a custom `SystemBackdropConfiguration` that incorporates some of the tracked property states but is different in some way from the default policy. First, obtain a `SystemBackdropConfiguration` object from `GetDefaultSystemBackdropConfiguration` as usual, but do not apply it via `CompositionController.SetSystemBackdropConfiguration`. Instead create an additional `SystemBackdropConfiguration` object that is updated on `OnDefaultSystemBackdropConfigurationChanged` by applying custom logic to the tracked property (eg ignoring Theme change). The second `SystemBackdropConfiguration` object is hooked up to `CompositionController.SetSystemBackdropConfiguration`, applying the custom policy.
0 commit comments