* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
4.4 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||
|---|---|---|---|---|---|---|---|---|---|
| How to: Transform a Brush | 03/30/2017 |
|
|
ebada2f9-f01f-4863-9ea2-c2e4e51610f1 |
How to: Transform a Brush
This example shows how to transform xref:System.Windows.Media.Brush objects by using their two transformation properties: xref:System.Windows.Media.Brush.RelativeTransform%2A and xref:System.Windows.Media.Brush.Transform%2A.
The following examples use a xref:System.Windows.Media.RotateTransform to rotate the content of an xref:System.Windows.Media.ImageBrush by 45 degrees.
The following illustration shows the xref:System.Windows.Media.ImageBrush without a xref:System.Windows.Media.RotateTransform, with the xref:System.Windows.Media.RotateTransform applied to the xref:System.Windows.Media.Brush.RelativeTransform%2A property, and with the xref:System.Windows.Media.RotateTransform applied to the xref:System.Windows.Media.Brush.Transform%2A property.
Example
The first example applies a xref:System.Windows.Media.RotateTransform to the xref:System.Windows.Media.Brush.RelativeTransform%2A property of an xref:System.Windows.Media.ImageBrush. The xref:System.Windows.Media.RotateTransform.CenterX%2A and xref:System.Windows.Media.RotateTransform.CenterY%2A properties of a xref:System.Windows.Media.RotateTransform object are both set to 0.5, which is the relative coordinate of the center point of this content. As a result, the xref:System.Windows.Media.ImageBrush content rotates about its center.
[!code-csharpBrushesIntroduction_snip#ImageBrushRelativeTransformExample] [!code-vbBrushesIntroduction_snip#ImageBrushRelativeTransformExample] [!code-xamlBrushesIntroduction_snip#ImageBrushRelativeTransformExample]
The second example also applies a xref:System.Windows.Media.RotateTransform to an xref:System.Windows.Media.ImageBrush; however, this example uses the xref:System.Windows.Media.Brush.Transform%2A property instead of the xref:System.Windows.Media.Brush.RelativeTransform%2A property.
To rotate the brush about its center, the example sets the xref:System.Windows.Media.RotateTransform.CenterX%2A and xref:System.Windows.Media.RotateTransform.CenterY%2A properties of the xref:System.Windows.Media.RotateTransform object to absolute coordinates. Because the brush paints a rectangle that is 175 by 90 pixels, the center point of the rectangle is (87.5, 45).
[!code-csharpBrushesIntroduction_snip#ImageBrushTransformExample] [!code-vbBrushesIntroduction_snip#ImageBrushTransformExample] [!code-xamlBrushesIntroduction_snip#ImageBrushTransformExample]
For a description of how the xref:System.Windows.Media.Brush.RelativeTransform%2A and xref:System.Windows.Media.Brush.Transform%2A properties work, see the Brush Transformation Overview.
For the complete sample, see Brushes Sample. For more information about brushes, see Painting with Solid Colors and Gradients Overview.
