Gets or sets the position and dimensions of the content in a TileBrush tile.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
When you paint an area by using a TileBrush, you use three components: content, tiles, and the output area. The property specifies the size and position of TileBrush content. The following illustration shows how these three TileBrush components relate to each other.
You can specify the size and position of TileBrush content by using the property. The ViewboxUnits property determines whether the value is relative to the bounds of the TileBrush content or whether it is an absolute value.
The first illustration shows a 100 by 100 pixel image and then uses this image to show the effects of different property settings.
The following illustration shows the output of a TileBrush that uses a of 0.0,0.0, 0.25,0.5. Other relevant property values include the following:
The next illustration shows a similar TileBrush but with a relative of 0.5,0.25, 0.25,0.5.
The following example shows how to create a tiled TileBrush that has a of 0.5,0.25, 0.25,0.5.
<Rectangle Width="100" Height="100"> <Rectangle.Fill> <ImageBrush ImageSource="sampleImages\testImage.gif" Viewbox="0.5,0.25, 0.25,0.5" ViewboxUnits="RelativeToBoundingBox" Viewport="0,0,0.5,0.5" ViewportUnits="RelativeToBoundingBox" TileMode="Tile" Stretch="Fill" AlignmentX="Center" AlignmentY="Center"/> </Rectangle.Fill> </Rectangle>
// Create a rectangle. Rectangle myRectangle = new Rectangle(); myRectangle.Width = 100; myRectangle.Height = 100; // Load the image. BitmapImage theImage = new BitmapImage( new Uri("sampleImages\\testImage.gif", UriKind.Relative)); ImageBrush myImageBrush = new ImageBrush(theImage); myImageBrush.Viewbox = new Rect(0.5, 0.25, 0.25, 0.5); myImageBrush.ViewboxUnits = BrushMappingMode.RelativeToBoundingBox; myImageBrush.Viewport = new Rect(0,0,0.25,0.25); myImageBrush.ViewportUnits = BrushMappingMode.RelativeToBoundingBox; myImageBrush.TileMode = TileMode.Tile; myImageBrush.Stretch = Stretch.Fill; myImageBrush.AlignmentX = AlignmentX.Center; myImageBrush.AlignmentY = AlignmentY.Center; // Use the ImageBrush to paint the rectangle's background. myRectangle.Fill = myImageBrush;