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: hub/apps/develop/composition/visual-layer.md
+50-12Lines changed: 50 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,16 @@
1
1
---
2
-
title: Visual layer for WinUI apps
3
-
description: The Microsoft.UI.Composition API gives your WinUI and Windows App SDK apps access to the composition layer between the framework layer (XAML) and the graphics layer (DirectX).
2
+
title: Visual layer overview
3
+
description: The Microsoft.UI.Composition Visual layer provides a high performance, retained-mode API for graphics, effects, animations, and input for WinUI and Windows App SDK apps.
4
4
ms.date: 03/16/2026
5
5
ms.topic: article
6
6
ms.localizationpriority: medium
7
7
---
8
-
# Visual layer for WinUI apps
8
+
# Visual layer overview
9
9
10
10
The Visual layer provides a high performance, retained-mode API for graphics, effects, and animations, and is the foundation for all UI across Windows devices. You define your UI in a declarative manner, and the Visual layer relies on graphics hardware acceleration to ensure your content, effects, and animations are rendered in a smooth, glitch-free manner independent of the app's UI thread.
11
11
12
+
The types in [Microsoft.UI.Composition](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition) form the Windows App SDK/WinUI 3 implementation of the Visual layer.
13
+
12
14
Notable highlights:
13
15
14
16
* Familiar WinRT APIs
@@ -30,7 +32,7 @@ The primary functions of the Visual layer are:
30
32
31
33
### Content
32
34
33
-
Content is hosted, transformed and made available for use by the animation and effects system using visuals. At the base of the class hierarchy is the [**Visual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.visual) class, a lightweight, thread-agile proxy in the app process for visual state in the compositor. Sub-classes of Visual include[**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual) to allow for children to create trees of visuals and [**SpriteVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.spritevisual) that contains content and can be painted with either solid colors, custom drawn content or visual effects. Together, these Visual types make up the visual tree structure for 2D UI and back most visible XAML FrameworkElements.
35
+
Content is hosted, transformed and made available for use by the animation and effects system using visuals. At the base of the class hierarchy is the [**Visual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.visual) class, a lightweight, thread-agile proxy in the app process for visual state in the compositor. Sub-classes of Visual include[**ContainerVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.containervisual) to allow for children to create trees of visuals and [**SpriteVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.spritevisual) that contains content and can be painted with either solid colors, custom drawn content or visual effects. Together, these Visual types make up the visual tree structure for 2D UI and back most visible XAML FrameworkElements.
34
36
35
37
For more information, see the [Composition Visual](composition-visual-tree.md) overview.
36
38
@@ -44,25 +46,61 @@ For more information, see the [Composition Effects](composition-effects.md) over
44
46
45
47
### Animations
46
48
47
-
The animation system in the Visual layer lets you move visuals, animate effects, and drive transformations, clips, and other properties.It is a framework agnostic system that has been designed from the ground up with performance in mind.It runs independently from the UI thread to ensure smoothness and scalability. While it lets you use familiar KeyFrame animations to drive property changes over time, it also lets you set up mathematical relationships between different properties, including user input, letting you directly craft seamless choreographed experiences.
49
+
The animation system in the Visual layer lets you move visuals, animate effects, and drive transformations, clips, and other properties.It is a framework agnostic system that has been designed from the ground up with performance in mind.It runs independently from the UI thread to ensure smoothness and scalability. While it lets you use familiar KeyFrame animations to drive property changes over time, it also lets you set up mathematical relationships between different properties, including user input, letting you directly craft seamless choreographed experiences.
48
50
49
51
For more information, see the [Composition animations](composition-animation.md) overview.
50
52
51
-
###Working with WinUI XAML
53
+
## Working with WinUI XAML
52
54
53
55
You can get to a Visual created by the XAML framework, and backing a visible FrameworkElement, by using the [**ElementCompositionPreview**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.hosting.elementcompositionpreview) class in [**Microsoft.UI.Xaml.Hosting**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.hosting). Note that Visuals created for you by the framework come with some limits on customization. This is because the framework is managing offsets, transforms, and lifetimes. You can, however, create your own Visuals and attach them to an existing WinUI element via ElementCompositionPreview, or by adding them to an existing ContainerVisual somewhere in the visual tree structure.
54
56
55
57
For more information, see the [Using the Visual layer with XAML](using-the-visual-layer-with-xaml.md) overview.
56
58
57
-
###Working with your desktop app
59
+
## Working with your desktop app
58
60
59
61
You can use the Visual layer to enhance the look, feel, and functionality of Win32 desktop apps built with the Windows App SDK, as well as WPF, Windows Forms, and C++ Win32 desktop apps. You can migrate islands of content to use the Visual layer and keep the rest of your UI in its existing framework. This means you can make significant updates and enhancements to your application UI without needing to make extensive changes to your existing code base.
60
62
61
63
For more information, see [Modernize your desktop app using the Visual layer](/windows/apps/desktop/modernize/visual-layer-in-desktop-apps).
62
64
63
-
## Additional resources
65
+
## Differences from UWP
66
+
67
+
The **Microsoft.UI.Composition** namespace provides access to functionality that's nearly identical to the UWP Visual layer (**Windows.UI.Composition**), in the most commonly used scenarios. But there are exceptions and differences.
68
+
69
+
### Getting a Compositor instance
70
+
71
+
In desktop apps (a WinUI app is a desktop app), **Window.Current** is `null`. So you can't retrieve an instance of [Compositor](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositor) from `Window.Current.Compositor`. In WinUI apps, we recommend that you call [ElementCompositionPreview.GetElementVisual(UIElement)](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.hosting.elementcompositionpreview.getelementvisual) to get a Composition [Visual](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.visual), and retrieve the `Compositor` from the visual's [Compositor](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionobject.compositor) property. In cases where you don't have access to a **UIElement** (for example, if you create a [CompositionBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionbrush) in a class library), you can call [CompositionTarget.GetCompositorForCurrentThread](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.compositiontarget.getcompositorforcurrentthread).
72
+
73
+
### External content
74
+
75
+
The **Microsoft.UI.Composition** compositor runs entirely within a Windows App SDK app and has access only to pixels that it drew. That means that any *external* content (content that wasn't drawn by the compositor) is unknown to the compositor, which creates certain limitations.
76
+
77
+
An example of external content is the (**Microsoft.UI.Xaml.Controls**) [MediaPlayerElement](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.mediaplayerelement). The Windows media stack provides to XAML an opaque media swap chain handle. XAML gives that handle to the compositor, which in turn hands it off to Windows (via **Windows.UI.Composition**) to display. Since the compositor can't see any of the pixels in the media swap chain, it can't composite that as part of the overall rendering for the window. Instead, it gives the media swap chain to Windows to render it below the compositor's rendering, with a hole cut out of the compositor's rendering in order to allow the media swap chain below it to be visible.
78
+
79
+
[](../windows-app-sdk/images/external-content.png#lightbox)
80
+
81
+
In the Windows App SDK/WinUI, the following APIs all create external content:
*[MicaBackdrop](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.micabackdrop) and [DesktopAcrylicBackdrop](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.desktopacrylicbackdrop), as well as the underlying [MicaController](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.micacontroller) and [DesktopAcrylicController](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.systembackdrops.desktopacryliccontroller) that they use.
87
+
88
+
The model of handling external content creates these limitations:
89
+
90
+
* It's not possible to have compositor content behind external content. For example, it's not possible to give a **WebView2** a transparent background in order to see XAML buttons or images behind it. The only things that can be behind external content are *other* external content and the window background. Because of that, we discourage/disable transparency for external content.
91
+
* It's not possible to have compositor content sample from external content. For example, [AcrylicBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.acrylicbrush) isn't able to sample and blur any pixels from a **MediaPlayerElement**. **AcrylicBrush** will sample from the compositor's image, which is transparent black for external content areas. Similarly, **AcrylicBrush** in front of a **MicaBackdrop** or **DesktopAcrylicBackdrop** can't see any colors that those backdrops will draw; and instead, the brush will blur the transparent black.
92
+
* Another scenario is known as *destination invert*, which is used for the caret of text box controls to invert the pixels that the text insertion caret is in front of. That invert similarly samples from the compositor surface, and it will be impacted if the text box doesn't have an opaque background that's drawn by the compositor.
93
+
* Because the WinUI [SwapChainPanel](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.swapchainpanel) creates external content, it doesn't support transparency. Nor does it support applying [AcrylicBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.acrylicbrush) and other effects that use a [CompositionBackdropBrush](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition.compositionbackdropbrush) in front of it.
94
+
95
+
## Samples
96
+
97
+
The Windows App SDK Samples project includes a comprehensive set of composition samples that demonstrate how to use the **Microsoft.UI.Composition** APIs to build rich visual experiences. These samples cover a wide range of scenarios — from basic layout and transforms to advanced effects, lighting, shadows, and InteractionTracker-based input handling like pull-to-refresh and parallax scrolling. Whether you're getting started with the Visual layer or looking for patterns to apply in your own app, these samples are a practical reference for seeing how the building blocks come together.
98
+
99
+
Explore the samples on GitHub: [WindowsAppSDK-Samples / SceneGraph](https://github.com/microsoft/WindowsAppSDK-Samples/tree/main/Samples/SceneGraph).
*[**Full reference documentation for the API**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition)
66
-
* Advanced UI and Composition samples in the [Windows Composition Samples GitHub](https://github.com/microsoft/WindowsCompositionSamples)
67
-
* Explore WinUI controls and patterns in the [WinUI Gallery](https://github.com/microsoft/WinUI-Gallery)
68
-
* Read Kenny Kerr's MSDN article on this API: [Graphics and Animation - Windows Composition Turns 10](/archive/msdn-magazine/2015/windows-10-special-issue/graphics-and-animation-windows-composition-turns-10)
105
+
*[**Microsoft.UI.Composition API reference**](/windows/windows-app-sdk/api/winrt/microsoft.ui.composition)
106
+
*[Using the Visual layer in desktop apps](../desktop/modernize/ui/visual-layer-in-desktop-apps.md)
Copy file name to clipboardExpand all lines: hub/apps/develop/graphics.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ The following articles provide information about features available via WinRT AP
32
32
33
33
| Article | Description |
34
34
|---------|-------------|
35
-
|[Visual layer](../windows-app-sdk/composition.md)| Learn how to use the visual layer in UWP apps. The visual layer provides a high performance, retained-mode API for graphics, effects and animations, and is the foundation for all WinRT XAML-based UI in Windows apps. |
35
+
|[Visual layer](composition/visual-layer.md)| Learn how to use the Visual layer in WinUI and Windows App SDK apps. The Visual layer provides a high performance, retained-mode API for graphics, effects and animations, and is the foundation for all WinRT XAML-based UI in Windows apps. |
36
36
|[Using the Visual layer in desktop apps](../desktop/modernize/ui/visual-layer-in-desktop-apps.md)| Learn how to use the visual layer in WPF, Windows Forms, and C++ Win32 apps. |
37
37
|[XAML platform](/windows/apps/develop/platform/xaml/)| Learn the fundamentals of the XAML language and concepts for WinRT-based graphic components Windows apps. |
0 commit comments