Skip to content

Commit d4c8321

Browse files
authored
remove outdated info from brushes (#5938)
* remove outdated info from brushes * fix link
1 parent 8ad5d94 commit d4c8321

1 file changed

Lines changed: 32 additions & 33 deletions

File tree

hub/apps/develop/platform/xaml/brushes.md

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
ms.assetid: 02141F86-355E-4046-86EA-2A89D615B7DB
33
title: Use brushes
44
description: Brush objects are used to paint the interiors or outlines of shapes, text, and parts of controls, so that the object being painted is visible in a UI.
5-
ms.date: 04/28/2020
5+
ms.date: 10/31/2025
66
ms.topic: how-to
7-
keywords: windows 10, uwp
87
ms.localizationpriority: medium
98
---
109
# Using brushes to paint backgrounds, foregrounds, and outlines
1110

1211
Use [**Brush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.Brush) objects to paint the interiors and outlines of XAML shapes, text, and controls, making them visible in your application UI.
1312

14-
> **Important APIs**: [Brush class](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.Brush)
13+
> [!div class="checklist"]
14+
>
15+
> - **Important APIs**: [Brush class](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.Brush), [SolidColorBrush class](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.SolidColorBrush), [RadialGradientBrush class](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.radialgradientbrush), [ImageBrush class](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.ImageBrush)
16+
17+
> [!div class="nextstepaction"]
18+
> [Open the WinUI 3 Gallery app and see the RadialGradientBrush in action](winui3gallery://item/RadialGradientBrush)
19+
20+
[!INCLUDE [winui-3-gallery](../../../../includes/winui-3-gallery.md)]
1521

1622
## Introduction to brushes
1723

@@ -24,7 +30,6 @@ The different types of brushes are:
2430
- [**LinearGradientBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.LinearGradientBrush)
2531
- [**RadialGradientBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.radialgradientbrush)
2632
- [**ImageBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.ImageBrush)
27-
- [**WebViewBrush**](/uwp/api/windows.ui.xaml.controls.webviewbrush) (UWP only)
2833
- [**XamlCompositionBrushBase**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.xamlcompositionbrushbase)
2934

3035
## Solid color brushes
@@ -107,20 +112,6 @@ The color of each point between gradient stops is linearly interpolated as a com
107112

108113
You can change the line at which the gradient stops are positioned by setting the [**StartPoint**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.lineargradientbrush.startpoint) and [**EndPoint**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.lineargradientbrush.endpoint) properties to be different values than the `(0,0)` and `(1,1)` starting defaults. By changing the **StartPoint** and **EndPoint** coordinate values, you can create horizontal or vertical gradients, reverse the gradient direction, or condense the gradient spread to apply to a smaller range than the full painted area. To condense the gradient, you set values of **StartPoint** and/or **EndPoint** to be something that is between the values 0 and 1. For example, if you want a horizontal gradient where the fade all happens on the left half of the brush and the right side is solid to your last [**GradientStop**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.GradientStop) color, you specify a **StartPoint** of `(0,0)` and an **EndPoint** of `(0.5,0)`.
109114

110-
### Use tools to make gradients
111-
112-
Now that you know how linear gradients work, you can use Visual Studio or Blend to make creating these gradients easier. To create a gradient, select the object you want to apply a gradient to on the design surface or in XAML view. Expand **Brush** and select the **Linear Gradient** tab.
113-
114-
![Create linear gradient in Visual Studio](images/tool-gradient-brush-1.png)
115-
116-
*Creating a linear gradient in Visual Studio*
117-
118-
Now you can change the colors of the gradient stops and slide their positions using the bar on the bottom. You can also add new gradient stops by clicking on the bar and remove them by dragging the stops off of the bar (see next screenshot).
119-
120-
![Bar at bottom of properties window that controls gradient stops](images/tool-gradient-brush-2.png)
121-
122-
*Gradient setting slider*
123-
124115
## Radial gradient brushes
125116

126117
A [**RadialGradientBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.radialgradientbrush) is drawn within an ellipse that is defined by the [**Center**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.radialgradientbrush.center), [**RadiusX**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.radialgradientbrush.radiusx), and [**RadiusY**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.radialgradientbrush.radiusy) properties. Colors for the gradient start at the center of the ellipse and end at the radius.
@@ -187,10 +178,6 @@ You can also use brushes to apply rendering characteristics to text elements. Fo
187178

188179
Even when you use a solid color, make sure that the text color you choose has enough contrast against the background color of the text's layout container. The level of contrast between text foreground and text container background is an accessibility consideration.
189180

190-
## WebViewBrush (UWP only)
191-
192-
A [**WebViewBrush**](/uwp/api/windows.ui.xaml.controls.webviewbrush) is a special type of brush that can access the content normally viewed in a [**WebView**](/uwp/api/windows.ui.xaml.controls.webview) control. Instead of rendering the content in the rectangular **WebView** control area, **WebViewBrush** paints that content onto another element that has a [**Brush**](/uwp/api/windows.ui.xaml.Media.Brush)-type property for a render surface. **WebViewBrush** isn't appropriate for every brush scenario, but is useful for transitions of a **WebView**. For more info, see [**WebViewBrush**](/uwp/api/windows.ui.xaml.controls.webviewbrush).
193-
194181
## XamlCompositionBrushBase
195182

196183
[**XamlCompositionBrushBase**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.xamlcompositionbrushbase) is a base class used to create custom brushes that use [**CompositionBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.Composition.CompositionBrush) to paint XAML UI elements.
@@ -217,21 +204,33 @@ To create a [**SolidColorBrush**](/windows/windows-app-sdk/api/winrt/microsoft.u
217204
SolidColorBrush blueBrush = new SolidColorBrush(Colors.Blue);
218205
```
219206

220-
```vb
221-
Dim blueBrush as SolidColorBrush = New SolidColorBrush(Colors.Blue)
222-
```
223-
224207
```cppwinrt
225208
Microsoft::UI::Xaml::Media::SolidColorBrush blueBrush{ Microsoft::UI::Colors::Blue() };
226209
```
227210

228-
```cpp
229-
blueBrush = ref new SolidColorBrush(Windows::UI::Colors::Blue);
230-
```
211+
For [**ImageBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.ImageBrush), use the default constructor and then call other APIs before you attempt to use that brush for a UI property.
212+
213+
[**ImageSource**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.imagebrush.imagesourceproperty) requires a [**BitmapImage**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.Imaging.BitmapImage) (not a URI) when you define an [**ImageBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.ImageBrush) using code. If your source is a stream , use the [**SetSourceAsync**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.imaging.bitmapsource.setsourceasync) method to initialize the value. If your source is a URI, which includes content in your app that uses the **ms-appx** or **ms-resource** schemes, use the [**BitmapImage**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.imaging.bitmapimage) constructor that takes a URI. You might also consider handling the [**ImageOpened**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.imagebrush.imageopened) event if there are any timing issues with retrieving or decoding the image source, where you might need alternate content to display until the image source is available.
214+
215+
For code examples, see [**ImageBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.ImageBrush) and [**XamlCompositionBrushBase**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.xamlcompositionbrushbase).
216+
217+
## UWP and WinUI 2
231218

232-
For [**WebViewBrush**](/uwp/api/windows.ui.xaml.controls.webviewbrush) and [**ImageBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.ImageBrush), use the default constructor and then call other APIs before you attempt to use that brush for a UI property.
219+
[!INCLUDE [uwp-winui2-note](../../../../includes/uwp-winui-2-note.md)]
220+
221+
Brush APIs exist in the [Windows.UI.Xaml.Controls](/uwp/api/Windows.UI.Xaml.media) and [Windows.UI.Xaml.Controls](/uwp/api/windows.ui.xaml.controls) namespaces.
222+
223+
> [!div class="checklist"]
224+
>
225+
> - **Platform APIs:** [Brush class](/uwp/api/windows.ui.xaml.media.brush)
226+
> - [Open the WinUI 2 Gallery app and see RadialGradientBrush in action](winui2gallery:/item/RadialGradientBrush). [!INCLUDE [winui-2-gallery](../../../../includes/winui-2-gallery.md)]
227+
228+
We recommend using the latest [WinUI 2](/windows/uwp/get-started/winui2/) to get the most current styles, templates, and features for all controls.
229+
230+
### WebViewBrush (UWP only)
231+
232+
A [**WebViewBrush**](/uwp/api/windows.ui.xaml.controls.webviewbrush) is a special type of brush that can access the content normally viewed in a [**WebView**](/uwp/api/windows.ui.xaml.controls.webview) control. Instead of rendering the content in the rectangular **WebView** control area, **WebViewBrush** paints that content onto another element that has a [**Brush**](/uwp/api/windows.ui.xaml.Media.Brush)-type property for a render surface. **WebViewBrush** isn't appropriate for every brush scenario, but is useful for transitions of a **WebView**. For more info, see [**WebViewBrush**](/uwp/api/windows.ui.xaml.controls.webviewbrush).
233233

234-
- [**ImageSource**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.imagebrush.imagesourceproperty) requires a [**BitmapImage**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.Imaging.BitmapImage) (not a URI) when you define an [**ImageBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.ImageBrush) using code. If your source is a stream , use the [**SetSourceAsync**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.imaging.bitmapsource.setsourceasync) method to initialize the value. If your source is a URI, which includes content in your app that uses the **ms-appx** or **ms-resource** schemes, use the [**BitmapImage**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.imaging.bitmapimage) constructor that takes a URI. You might also consider handling the [**ImageOpened**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.imagebrush.imageopened) event if there are any timing issues with retrieving or decoding the image source, where you might need alternate content to display until the image source is available.
235-
- For [**WebViewBrush**](/uwp/api/windows.ui.xaml.controls.webviewbrush) you might need to call [**Redraw**](/uwp/api/windows.ui.xaml.controls.webviewbrush.redraw) if you've recently reset the [**SourceName**](/uwp/api/windows.ui.xaml.controls.webviewbrush.sourcename) property or if the content of the [**WebView**](/uwp/api/windows.ui.xaml.controls.webview) is also being changed with code.
234+
If you create a [**WebViewBrush**](/uwp/api/windows.ui.xaml.controls.webviewbrush) in code, use the default constructor and then call other APIs before you attempt to use that brush for a UI property. You might need to call [**Redraw**](/uwp/api/windows.ui.xaml.controls.webviewbrush.redraw) if you've recently reset the [**SourceName**](/uwp/api/windows.ui.xaml.controls.webviewbrush.sourcename) property or if the content of the [**WebView**](/uwp/api/windows.ui.xaml.controls.webview) is also being changed with code.
236235

237-
For code examples, see [**WebViewBrush**](/uwp/api/windows.ui.xaml.controls.webviewbrush), [**ImageBrush**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.Media.ImageBrush), and [**XamlCompositionBrushBase**](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.media.xamlcompositionbrushbase).
236+
For code examples, see [**WebViewBrush**](/uwp/api/windows.ui.xaml.controls.webviewbrush).

0 commit comments

Comments
 (0)