Gets or sets a value that specifies how the content of this TileBrush stretches to fit its tiles.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
The property accepts the following values, which the Stretch enumeration defines:
Fill: The TileBrush content is scaled to fit the tile. Because the content's height and width are scaled independently, the original aspect ratio of the content might not be preserved. That is, the TileBrush content might be distorted in order to completely fill the output tile.
The following image illustrates the different settings.
The following illustration shows the effect of different settings on a TileBrush that has a Viewbox that is smaller than its Viewport. The parts of the image that are outside the Viewbox are tinted gray.
This example shows how to use the property of an ImageBrush in order to preserve the aspect ratio of the image.
By default, when you use an ImageBrush to paint an area, its content stretches to completely fill the output area. When the output area and the image have different aspect ratios, the image is distorted by this stretching.
The following example uses two ImageBrush objects to paint two rectangles. Each rectangle is 300 by 150 pixels and each contains a 300 by 300 pixel image. The property of the first brush is set to Uniform, and the property of the second brush is set to UniformToFill.
<!-- Demonstrates different ImageBrush Stretch settings.--> <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="PresentationOptions" Background="White" Margin="20" Title="ImageBrush Stretch Modes"> <StackPanel> <!-- The ImageBrush in this example has its Stretch property set to Uniform. As a result, the image it contains is expanded as much as possible to fill the rectangle while still preserving its aspect ratio.--> <Rectangle Width="300" Height="150" Stroke="MediumBlue" StrokeThickness="1"> <Rectangle.Fill> <ImageBrush Stretch="Uniform" ImageSource="sampleImages\square.jpg" PresentationOptions:Freeze="True" /> </Rectangle.Fill> </Rectangle> <!-- The ImageBrush in this example has its Stretch property set to UniformToFill. As a result, the image is expanded to completely fill the rectangle, but its aspect ratio is preserved.--> <Rectangle Width="300" Height="150" Stroke="MediumBlue" StrokeThickness="1" Margin="0,10,0,0"> <Rectangle.Fill> <ImageBrush Stretch="UniformToFill" ImageSource="sampleImages\square.jpg" PresentationOptions:Freeze="True" /> </Rectangle.Fill> </Rectangle> </StackPanel> </Page>
The following illustration shows the output of the first brush, which has a setting of Uniform.
The next illustration shows the output of the second brush, which has a setting of UniformToFill.
Note that the property behaves identically for the other TileBrush objects, that is, for DrawingBrush and VisualBrush. For more information about ImageBrush and the other TileBrush objects, see Painting with Images, Drawings, and Visuals.
Note also that, although the property appears to specify how the TileBrush content stretches to fit its output area, it actually specifies how the TileBrush content stretches to fill its base tile. For more information, see TileBrush.
|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 TileBrush, use its AlignmentX and AlignmentY properties.|