* 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
2.7 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||
|---|---|---|---|---|---|---|---|---|---|
| How to: Paint an Area with an Image | 03/30/2017 |
|
|
3432c533-1fc7-492d-94ee-0b13d60125ae |
How to: Paint an Area with an Image
This example shows how to use the xref:System.Windows.Media.ImageBrush class to paint an area with an image. An xref:System.Windows.Media.ImageBrush displays a single image, which is specified by its xref:System.Windows.Media.ImageBrush.ImageSource%2A property.
Example
The following example paints the xref:System.Windows.Controls.Control.Background%2A of a button by using an xref:System.Windows.Media.ImageBrush.
[!code-csharpUsingImageBrush_snip#ImageBrushExampleWholePage]
By default, an xref:System.Windows.Media.ImageBrush stretches its image to completely fill the area that you are painting. In the preceding example, the image is stretched to fill the button, possibly distorting the image. You can control this behavior by setting the xref:System.Windows.Media.TileBrush.Stretch%2A property of xref:System.Windows.Media.TileBrush to xref:System.Windows.Media.Stretch.Uniform or xref:System.Windows.Media.Stretch.UniformToFill, which causes the brush to preserve the aspect ratio of the image.
If you set the xref:System.Windows.Media.TileBrush.Viewport%2A and xref:System.Windows.Media.TileBrush.TileMode%2A properties of an xref:System.Windows.Media.ImageBrush, you can create a repeating pattern. The following example paints a button by using a pattern that is created from an image.
[!code-csharpUsingImageBrush_snip#TiledImageBrushExampleWholePage] [!code-vbUsingImageBrush_snip#TiledImageBrushExampleWholePage]
For more information about the xref:System.Windows.Media.ImageBrush class, see Painting with Images, Drawings, and Visuals.
This code example is part of a larger example that is provided for the xref:System.Windows.Media.ImageBrush class. For the complete sample, see ImageBrush Sample.