Use VisualBrush to paint background

image_pdfimage_print


   
     

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  x:Class="Microsoft.Samples.Graphics.UsingVisualBrush.PaintingWithVisuals">
    <StackPanel>
        <StackPanel.Background>
            <VisualBrush Opacity="0.1" Viewport="0,0,250,30" ViewportUnits="Absolute" TileMode="Tile" Stretch="None">
                <VisualBrush.Visual>
                    <Border Width="250" Background="Transparent">
                        <TextBlock Margin="5" FontSize="60px" >
              VisualBrush
              <TextBlock.Foreground>
                <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                  <LinearGradientBrush.GradientStops>
                    <GradientStop Offset="0.0" Color="Black" />
                    <GradientStop Offset="1.0" Color="Red" />
                  </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
              </TextBlock.Foreground>
                        </TextBlock>
                    </Border>
                </VisualBrush.Visual>
                <VisualBrush.RelativeTransform>
                    <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5" />
                </VisualBrush.RelativeTransform>
            </VisualBrush>
        </StackPanel.Background>
    </StackPanel>
</Page>

   
    
    
    
    
     


Tile VisualBrush

image_pdfimage_print


   
     
<Page  
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  x:Class="Microsoft.Samples.Graphics.UsingVisualBrush.PaintingWithVisuals">
    <StackPanel>
        <Rectangle Width="150" Height="150" Stroke="Black" Margin="0,0,5,0">
            <Rectangle.Fill>
                <VisualBrush Viewport="0,0,95,35" ViewportUnits="Absolute" TileMode="Tile">
                    <VisualBrush.Visual>
                        <StackPanel Background="Transparent">
                            <TextBlock FontSize="10pt" Margin="10">Hello, World!</TextBlock>
                        </StackPanel>
                    </VisualBrush.Visual>
                </VisualBrush>
            </Rectangle.Fill>
        </Rectangle>
    </StackPanel>
</Page>

   
    
    
    
    
     


VisualBrush Binding to a Button

image_pdfimage_print


   
     
<Window x:Class="Drawing.VisualBrush"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="VisualBrush" Height="300" Width="300"
    >
  <StackPanel Margin="3">
    <Button Name="cmd" Margin="3" Padding="5">Is this a real button?</Button>
    <Rectangle Margin="3" Height="{Binding ElementName=cmd,Path=ActualHeight}">
      <Rectangle.Fill>
        <VisualBrush Visual="{Binding ElementName=cmd}"></VisualBrush>
      </Rectangle.Fill>
    </Rectangle>
    <Rectangle Margin="3" Height="50">
      <Rectangle.Fill>
        <VisualBrush Visual="{Binding ElementName=cmd}"></VisualBrush>
      </Rectangle.Fill>
    </Rectangle>
    <Rectangle Margin="3" Height="150">
      <Rectangle.Fill>
        <VisualBrush Visual="{Binding ElementName=cmd}"></VisualBrush>
      </Rectangle.Fill>
    </Rectangle>
  </StackPanel>
</Window>

   
    
    
    
    
     


Basic DialogBox

image_pdfimage_print


   
      

<Window x:Class="Styles.BasicDialogBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="BasicDialogBox" Height="300" Width="300" MinHeight="150" MinWidth="200">
  <Window.Resources>
    <Thickness x:Key="BasicMargin" Bottom="5" Top="5" Left="5" Right="5"></Thickness>
  </Window.Resources>
  <DockPanel LastChildFill="True">
    <StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" Orientation="Horizontal">
      <Button Margin="{StaticResource BasicMargin}" Padding="3,3,3,3">OK</Button>
      <Button Margin="{StaticResource BasicMargin}" Padding="3,3,3,3">Cancel</Button>
      
    </StackPanel>
    <TextBox DockPanel.Dock="Top" Margin="10">This is a test.</TextBox>
  </DockPanel>
</Window>

   
    
    
    
    
    
     


Window ResizeMode=CanMinimize

image_pdfimage_print


   
      

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        Title="Compile XAML Only"
        SizeToContent="WidthAndHeight"
        ResizeMode="CanMinimize">
    <StackPanel>

        <Button HorizontalAlignment="Center"
                Margin="24">
            Just a Button
        </Button>

        <Ellipse Width="200"
                 Height="100"
                 Margin="24" 
                 Stroke="Red"
                 StrokeThickness="10" />

        <ListBox Width="100"
                 Height="100"
                 Margin="24">
            <ListBoxItem>Sunday</ListBoxItem>
            <ListBoxItem>Monday</ListBoxItem>
            <ListBoxItem>Tuesday</ListBoxItem>
            <ListBoxItem>Wednesday</ListBoxItem>
            <ListBoxItem>Thursday</ListBoxItem>
            <ListBoxItem>Friday</ListBoxItem>
            <ListBoxItem>Saturday</ListBoxItem>
        </ListBox>

    </StackPanel>
</Window>

   
    
    
    
    
    
     


Window Background

image_pdfimage_print


   
      

<Window x:Class="Drawing.OpacityMask"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="OpacityMask" Height="313.6" Width="317.6"
    >
  <Window.Background>
    <ImageBrush ImageSource="c:image.jpg"></ImageBrush>
  </Window.Background>
    <Grid Margin="10,50">

    </Grid>
</Window>

   
    
    
    
    
    
     


Set Window Height and Width

image_pdfimage_print


   
      



<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WrapPanelWindow" Height="300" Width="300">
    <WrapPanel>
        <Button Width="30">A</Button>
        <Button Width="30">B</Button>
        <Button Width="30">C</Button>
        <Button Width="30">D</Button>
        <Button Width="30">E</Button>
        <Button Width="30">F</Button>
        <Button Width="30">G</Button>
        <Button Width="30">H</Button>
        <Button Width="30">I</Button>
        <Button Width="30">J</Button>
        <Button Width="30">K</Button>
        <Button Width="30">L</Button>
        <Button Width="30">M</Button>
        <Button Width="30">N</Button>
        <Button Width="30">O</Button>
        <Button Width="30">P</Button>
    </WrapPanel>
</Window>