XAML VisualBrush
VisualBrush is a new addition to the brush types since GDI+. A VisualBrush is used to fill UI elements. This article shows how to use VisualBrush in XAML.
VisualBrush is a new addition to the brush types since GDI+. A VisualBrush is used to fill UI elements. The following code uses a VisualBrush to fill a rectangle. I will cover VisualBrush object, its methods and properties in more details in my seperate article.
<Rectangle Width="200" Height="100" Stroke="Black" StrokeThickness="1">
<Rectangle.Fill>
<VisualBrush Viewport="0,0,200,100" Viewbox="0,0,100,100"
ViewportUnits="Absolute" Stretch="Fill" >
<VisualBrush.Visual>
<Canvas>
<Grid Width="100" Height="100" >
<RowDefinition Height="20"/>
<RowDefinition Height="50"/>
<RowDefinition Height="30"/>
<Rectangle Grid.Row="0" Fill="Black"/>
<Rectangle Grid.Row="1" Fill="Yellow"/>
<Rectangle Grid.Row="2" Fill="Green"/>
</Grid>
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
</Rectangle.Fill>
</Rectangle>
|
The output looks like Figure 1.
Figure 1. Rectangle filled with a visual brush
Further Readings
You may also want to read these related articles.
Ask Your Question
Got a programming related question? You may want to post your question here