Files
docs-desktop/dotnet-desktop-guide/framework/wpf/graphics-multimedia/how-to-set-the-horizontal-and-vertical-alignment-of-a-tilebrush.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* 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
2020-09-04 09:46:28 -07:00

8.2 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Set the Horizontal and Vertical Alignment of a TileBrush 03/30/2017
csharp
vb
TileBrush [WPF], alignment of
vertical alignment of TileBrushes [WPF]
aligning [WPF], TileBrushes
horizontal alignment of Tilebrushes [WPF]
65ae89bd-9246-4c9e-bde4-2fb991d4060d

How to: Set the Horizontal and Vertical Alignment of a TileBrush

This example shows how to control the horizontal and vertical alignment of content in a tile. To control the horizontal and vertical alignment of a xref:System.Windows.Media.TileBrush, use its xref:System.Windows.Media.TileBrush.AlignmentX%2A and xref:System.Windows.Media.TileBrush.AlignmentY%2A properties.

The xref:System.Windows.Media.TileBrush.AlignmentX%2A and xref:System.Windows.Media.TileBrush.AlignmentY%2A properties of a xref:System.Windows.Media.TileBrush are used when either of the following conditions is true:

Example

The following example aligns the content of a xref:System.Windows.Media.DrawingBrush, which is a type of xref:System.Windows.Media.TileBrush, to the upper-left corner of its tile. To align the content, the example sets the xref:System.Windows.Media.TileBrush.AlignmentX%2A property of the xref:System.Windows.Media.DrawingBrush to xref:System.Windows.Media.AlignmentX.Left and the xref:System.Windows.Media.TileBrush.AlignmentY%2A property to xref:System.Windows.Media.AlignmentY.Top. This example produces the following output.

A TileBrush with top-left alignment
TileBrush with content aligned to the upper-left corner

[!code-csharpbrushoverviewexamples_snip#TileBrushTopLeftAlignmentInline] [!code-vbbrushoverviewexamples_snip#TileBrushTopLeftAlignmentInline] [!code-xamlbrushoverviewexamples_snip#TileBrushTopLeftAlignmentInline]

Example

The next example aligns the content of a xref:System.Windows.Media.DrawingBrush to the lower-right corner of its tile by setting the xref:System.Windows.Media.TileBrush.AlignmentX%2A property to xref:System.Windows.Media.AlignmentX.Right and the xref:System.Windows.Media.TileBrush.AlignmentY%2A property to xref:System.Windows.Media.AlignmentY.Bottom. The example produces the following output.

A TileBrush with bottom-right alignment
TileBrush with content aligned to the lower-right corner

[!code-csharpbrushoverviewexamples_snip#TileBrushBottomRightAlignmentInline] [!code-vbbrushoverviewexamples_snip#TileBrushBottomRightAlignmentInline] [!code-xamlbrushoverviewexamples_snip#TileBrushBottomRightAlignmentInline]

Example

The next example aligns the content of a xref:System.Windows.Media.DrawingBrush to the upper-left corner of its tile by setting the xref:System.Windows.Media.TileBrush.AlignmentX%2A property to xref:System.Windows.Media.AlignmentX.Left and the xref:System.Windows.Media.TileBrush.AlignmentY%2A property to xref:System.Windows.Media.AlignmentY.Top. It also sets the xref:System.Windows.Media.TileBrush.Viewport%2A and xref:System.Windows.Media.TileBrush.TileMode%2A of the xref:System.Windows.Media.DrawingBrush to produce a tile pattern. The example produces the following output.

A tiled TileBrush with top-left alignment
Tile pattern with content aligned to upper-left in base tile

The illustration highlights abase tile so that you can see how its content is aligned. Notice that the xref:System.Windows.Media.TileBrush.AlignmentX%2A setting has no effect because the content of the xref:System.Windows.Media.DrawingBrush completely fills the base tile horizontally.

[!code-csharpbrushoverviewexamples_snip#TileBrushTopLeftAlignmentTiledInline] [!code-vbbrushoverviewexamples_snip#TileBrushTopLeftAlignmentTiledInline] [!code-xamlbrushoverviewexamples_snip#TileBrushTopLeftAlignmentTiledInline]

Example

The final example aligns the content of a tiled xref:System.Windows.Media.DrawingBrush to the lower-right of its base tile by setting the xref:System.Windows.Media.TileBrush.AlignmentX%2A property to xref:System.Windows.Media.AlignmentX.Right and the xref:System.Windows.Media.TileBrush.AlignmentY%2A property to xref:System.Windows.Media.AlignmentY.Bottom. The example produces the following output.

A tiled TileBrush with bottom-right alignment
Tile pattern with content aligned to lower-right in base tile

Again, the xref:System.Windows.Media.TileBrush.AlignmentX%2A setting has no effect because the content of the xref:System.Windows.Media.DrawingBrush completely fills the base tile horizontally.

[!code-csharpbrushoverviewexamples_snip#TileBrushBottomRightAlignmentInline] [!code-vbbrushoverviewexamples_snip#TileBrushBottomRightAlignmentInline] [!code-xamlbrushoverviewexamples_snip#TileBrushBottomRightAlignmentInline]

The examples use xref:System.Windows.Media.DrawingBrush objects to demonstrate how the xref:System.Windows.Media.TileBrush.AlignmentX%2A and xref:System.Windows.Media.TileBrush.AlignmentY%2A properties are used. These properties behave identically for all the tile brushes: xref:System.Windows.Media.DrawingBrush, xref:System.Windows.Media.ImageBrush, and xref:System.Windows.Media.VisualBrush. For more information about tile brushes, see Painting with Images, Drawings, and Visuals.

See also