Paints an area with an image. The image source is typically obtained from file formats such as JPEG.
Inheritance
- Object
- DependencyObject
- Brush
- TileBrush
- ImageBrush
Syntax
<ImageBrush .../>
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- MarshalingBehaviorAttribute(Agile)
- StaticAttribute(Windows.UI.Xaml.Media.IImageBrushStatics, NTDDI_WIN8)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
- WebHostHiddenAttribute()
Members
The ImageBrush class has these types of members:
Constructors
The ImageBrush class has these constructors.
| Constructor | Description |
|---|---|
| ImageBrush | Initializes a new instance of the ImageBrush class. |
Events
The ImageBrush class has these events.
| Event | Description |
|---|---|
| ImageFailed | Occurs when there is an error associated with image retrieval or format. |
| ImageOpened | Occurs when the image source is downloaded and decoded with no failure. You can use this event to determine the size of an image before rendering it. |
Methods
The ImageBrush class has these methods. It also inherits methods from the Object class.
| Method | Description |
|---|---|
| ClearValue | Clears the local value of a dependency property. (Inherited from DependencyObject) |
| GetAnimationBaseValue | Returns any base value established for a dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject) |
| GetValue | Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject) |
| ReadLocalValue | Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject) |
| SetValue | Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject) |
Properties
The ImageBrush class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read/write | Gets or sets the horizontal alignment of content in the TileBrush base tile. (Inherited from TileBrush) | |
| Read/write | Gets or sets the vertical alignment of content in the TileBrush base tile. (Inherited from TileBrush) | |
| Read-only | Gets the CoreDispatcher that this object is associated with. (Inherited from DependencyObject) | |
| Read/write | Gets or sets the image displayed by this ImageBrush. | |
| Read-only | Identifies the ImageSource dependency property. | |
| Read/write | Gets or sets the degree of opacity of a Brush. (Inherited from Brush) | |
| Read/write | Gets or sets the transformation that is applied to the brush using relative coordinates. (Inherited from Brush) | |
| Read/write | Gets or sets a value that specifies how the content of this TileBrush stretches to fit its tiles. (Inherited from TileBrush) | |
| Read/write | Gets or sets the transformation that is applied to the brush. (Inherited from Brush) |
Remarks
An ImageBrush is a type of TileBrush that defines its content as an image. You can control how the image is stretched, aligned, and tiled, enabling you to produce patterns and other effects. Use for an ImageBrush include decorative effects for text, or tiled backgrounds for controls or layout containers.
If you define an ImageBrush using code, use the default constructor, then set ImageBrush.ImageSource. This requires a BitmapImage (not a URI) in code. If your source is a stream, use the SetSourceAsync method to initialize the value. If your source is a Uniform Resource Identifier (URI), which includes content in your app that uses the ms-appx or ms-resource schemes, use the BitmapImage constructor that takes a URI. You might also consider handling the ImageOpened event if there are any timing issues with retrieving or decoding the image source, where you might need alternate content to display until the image source is available. See XAML images sample for example code.
Note You can use automatic handling for accessing unqualified resources with current scale and culture qualifiers, or you can use ResourceManager and ResourceMap with qualifiers for culture and scale to obtain the resources directly. For more info see Resource management system.
The Stretch property is important for how the image is applied when used as a brush. Some images look good when stretched as applied to a particular Brush property with the Fill behavior whereas other images do not stretch or scale well and might require a value of None or Uniform for Stretch. Also some images are designed to tile whereas some are not. Experiment with different values for Stretch to see which behavior looks best when applied to the UI.
Image sources and scaling
You should create your image sources at several recommended sizes, to ensure that your app looks great when Windows 8 scales it. When specifying an ImageSource for an ImageBrush, you can use a naming convention that will automatically reference the correct resource for the current scaling. For specifics of the naming convention and more info, see Quickstart: Using file or image resources.
For more info on how to design for scaling, see Guidelines for scaling to pixel density.
Examples
This XAML example shows how to set the Foreground property of a TextBlock to an ImageBrush, whose image is used as the fill for the TextBlock-rendered text.
<!-- TextBlock with an image brush applied to the text. --> <TextBlock FontFamily="Verdana" FontSize="72" FontStyle="Italic" FontWeight="Bold"> SHRUBBERY <TextBlock.Foreground> <ImageBrush ImageSource="forest.jpeg"/> </TextBlock.Foreground> </TextBlock>
This illustration shows the results of this XAML example.
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 12/4/2012