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/using-the-visual-layer-with-xaml.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
---
2
-
title: Using the Visual Layer with WinUI XAML
2
+
title: Use the Visual Layer with WinUI XAML
3
3
description: Learn techniques for using the Visual Layer APIs with WinUI XAML content to create advanced animations and effects in Windows App SDK apps.
4
4
ms.date: 03/16/2026
5
5
ms.topic: how-to
6
6
ms.localizationpriority: medium
7
7
---
8
-
# Using the Visual Layer with WinUI XAML
8
+
# Use the Visual Layer with WinUI XAML
9
9
10
10
Most WinUI and Windows App SDK apps that consume Visual Layer capabilities will use XAML to define the main UI content. WinUI provides features in the XAML framework and the Visual Layer that make it easier to combine these two technologies to create stunning user experiences.
11
11
XAML and Visual Layer interop functionality can be used to create advanced animations and effects not available using XAML APIs alone. This includes:
@@ -19,17 +19,17 @@ XAML and Visual Layer interop functionality can be used to create advanced anima
19
19
These effects and animations can be applied to existing XAML content, so you don't have to dramatically restructure your WinUI app to take advantage of the functionality.
20
20
Layout animations, shadows, and blur effects are covered in the Recipes section below. For a code sample implementing parallax, see the [ParallaxingListItems sample](https://github.com/microsoft/WindowsCompositionSamples/tree/master/SampleGallery/Samples/SDK%2010586/ParallaxingListItems). The [WindowsCompositionSamples repository](https://github.com/microsoft/WindowsCompositionSamples) also has several other samples for implementing animations, shadows and effects.
21
21
22
-
## The Microsoft.UI.Xaml.Media.XamlCompositionBrushBase class
22
+
## The XamlCompositionBrushBase class
23
23
24
-
**XamlCompositionBrushBase** provides a base class for XAML brushes that paint an area with a **CompositionBrush**. This can be used to easily apply composition effects like blur or frosted glass to XAML UI elements.
24
+
**Microsoft.UI.Xaml.Media.XamlCompositionBrushBase** provides a base class for XAML brushes that paint an area with a **CompositionBrush**. This can be used to easily apply composition effects like blur or frosted glass to XAML UI elements.
25
25
26
26
See the [**Brushes**](/windows/apps/design/style/brushes#xamlcompositionbrushbase) section for more info on using brushes with XAML UI.
27
27
28
28
For code examples, see the reference page for [**XamlCompositionBrushBase**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.xamlcompositionbrushbase).
29
29
30
-
## The Microsoft.UI.Xaml.Media.XamlLight class
30
+
## The XamlLight class
31
31
32
-
**XamlLight** provides a base class for XAML lighting effects that dynamically light an area with a **CompositionLight**.
32
+
**Microsoft.UI.Xaml.Media.XamlLight** provides a base class for XAML lighting effects that dynamically light an area with a **CompositionLight**.
33
33
34
34
See the [**Lighting**](xaml-lighting.md) section for more info on using lights, including lighting XAML UI elements.
35
35
@@ -44,15 +44,15 @@ For code examples, see the reference page for [**XamlLight**](/windows/windows-a
44
44
-[**GetElementChildVisual**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.hosting.elementcompositionpreview.getelementchildvisual): Retrieve the Visual set using **SetElementChildVisual**
45
45
-[**GetScrollViewerManipulationPropertySet**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.hosting.elementcompositionpreview.getscrollviewermanipulationpropertyset): Get an object that can be used to create 60fps animations based on scroll offset in a **ScrollViewer**
46
46
47
-
##Remarks on ElementCompositionPreview.GetElementVisual
47
+
### GetElementVisual
48
48
49
-
**ElementCompositionPreview.GetElementVisual** returns a “handout” Visual that is used to render the given **UIElement**. Properties such as **Visual.Opacity**, **Visual.Offset**, and **Visual.Size** are set by the XAML framework based on the state of the UIElement. This enables techniques such as implicit reposition animations (see *Recipes*).
49
+
**ElementCompositionPreview.GetElementVisual** returns a "handout" Visual that is used to render the given **UIElement**. Properties such as **Visual.Opacity**, **Visual.Offset**, and **Visual.Size** are set by the XAML framework based on the state of the UIElement. This enables techniques such as implicit reposition animations (see *Recipes*).
50
50
51
51
Note that since **Offset** and **Size** are set as the result of XAML framework layout, developers should be careful when modifying or animating these properties. Developers should only modify or animate Offset when the element’s top-left corner has the same position as that of its parent in layout. Size should generally not be modified, but accessing the property may be useful. For example, the Drop Shadow and Frosted Glass samples below use Size of a handout Visual as input to an animation.
52
52
53
53
As an additional caveat, updated properties of the handout Visual will not be reflected in the corresponding UIElement. So for example, setting **UIElement.Opacity** to 0.5 will set the corresponding handout Visual’s Opacity to 0.5. However, setting the handout Visual’s **Opacity** to 0.5 will cause the content to appear at 50% opacity, but will not change the value of the corresponding UIElement’s Opacity property.
54
54
55
-
### Example of **Offset** animation
55
+
### Example of Offset animation
56
56
57
57
#### Incorrect
58
58
@@ -82,11 +82,11 @@ ElementCompositionPreview.GetElementVisual(MyImage).StartAnimation("Offset", par
**ElementCompositionPreview.SetElementChildVisual** allows the developer to supply a “handin” Visual that will appear as part of an element’s Visual Tree. This allows developers to create a “Composition Island” where Visual-based content can appear inside a XAML UI. Developers should be conservative about using this technique because Visual-based content will not have the same accessibility and user experience guarantees of XAML content. Therefore, it is generally recommended that this technique only be used when necessary to implement custom effects such as those found in the Recipes section below.
88
88
89
-
## **GetAlphaMask** methods
89
+
## GetAlphaMask methods
90
90
91
91
[**Image**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.image), [**TextBlock**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.textblock), and [**Shape**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.shapes.shape) each implement a method called **GetAlphaMask** that returns a **CompositionBrush** representing a grayscale image with the shape of the element. This **CompositionBrush** can serve as an input for a Composition **DropShadow**, so the shadow can reflect the shape of the element instead of a rectangle. This enables pixel perfect, contour-based shadows for text, images with alpha, and shapes. See *Drop Shadow* below for an example of this API.
0 commit comments