Skip to content

Commit ce34b1b

Browse files
committed
Finetuning
1 parent 26d0629 commit ce34b1b

4 files changed

Lines changed: 53 additions & 78 deletions

File tree

hub/apps/develop/composition/visual-layer.md

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
---
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.
44
ms.date: 03/16/2026
55
ms.topic: article
66
ms.localizationpriority: medium
77
---
8-
# Visual layer for WinUI apps
8+
# Visual layer overview
99

1010
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.
1111

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+
1214
Notable highlights:
1315

1416
* Familiar WinRT APIs
@@ -30,7 +32,7 @@ The primary functions of the Visual layer are:
3032

3133
### Content
3234

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.
3436

3537
For more information, see the [Composition Visual](composition-visual-tree.md) overview.
3638

@@ -44,25 +46,61 @@ For more information, see the [Composition Effects](composition-effects.md) over
4446

4547
### Animations
4648

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.
4850

4951
For more information, see the [Composition animations](composition-animation.md) overview.
5052

51-
### Working with WinUI XAML
53+
## Working with WinUI XAML
5254

5355
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.
5456

5557
For more information, see the [Using the Visual layer with XAML](using-the-visual-layer-with-xaml.md) overview.
5658

57-
### Working with your desktop app
59+
## Working with your desktop app
5860

5961
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.
6062

6163
For more information, see [Modernize your desktop app using the Visual layer](/windows/apps/desktop/modernize/visual-layer-in-desktop-apps).
6264

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+
[![Diagram of rendering external content](../windows-app-sdk/images/external-content.png) ](../windows-app-sdk/images/external-content.png#lightbox)
80+
81+
In the Windows App SDK/WinUI, the following APIs all create external content:
82+
83+
* [MediaPlayerElement](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.mediaplayerelement)
84+
* [SwapChainPanel](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.swapchainpanel)
85+
* [WebView2](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.webview2)
86+
* [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).
100+
101+
![app gif](https://media.giphy.com/media/Hx2beMDfEA7QqWPvD4/giphy.gif)
102+
103+
## Related topics
64104

65-
* [**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)

hub/apps/develop/graphics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The following articles provide information about features available via WinRT AP
3232

3333
| Article | Description |
3434
|---------|-------------|
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. |
3636
| [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. |
3737
| [XAML platform](/windows/apps/develop/platform/xaml/) | Learn the fundamentals of the XAML language and concepts for WinRT-based graphic components Windows apps. |
3838

hub/apps/develop/toc.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,9 @@ items:
240240
items:
241241
- name: Overview
242242
href: graphics.md
243-
- name: Enhance UI with the Visual layer
244-
href: ../windows-app-sdk/composition.md
243+
- name: Visual layer
245244
items:
246-
- name: Visual layer overview
245+
- name: Overview
247246
href: composition/visual-layer.md
248247
- name: Composition visual
249248
href: composition/composition-visual-tree.md

0 commit comments

Comments
 (0)