Paints a rectangle with a grid pattern with VisualBrush

image_pdfimage_print


   
     
<Window x:Class="Workspace.DockExample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Workspace" Width="640" Height="480">
      <Rectangle Width="50" Height="50" Grid.Row="1" Grid.Column="1">
        <Rectangle.Fill>
          <VisualBrush Viewport="0,0,1,0.25" TileMode="Tile" Stretch="Uniform">
            <VisualBrush.Visual>
              <StackPanel Background="White">
                <TextBlock FontSize="10pt" Margin="1">Hello, World!</TextBlock>
              </StackPanel>
            </VisualBrush.Visual>
            <VisualBrush.RelativeTransform>
              <RotateTransform Angle="-45" CenterX="0.5" CenterY="0.5" />
            </VisualBrush.RelativeTransform>
          </VisualBrush>
        </Rectangle.Fill>
      </Rectangle>
</Window>