Simple Border

image_pdfimage_print


   
     

<Window x:Class="Content.SimpleBorder"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="SimpleBorder" Height="300" Width="300">
  <Border Margin="5" Padding="5" Background="LightYellow" 
          BorderBrush="SteelBlue" BorderThickness="3,5,3,5" CornerRadius="3"
          VerticalAlignment="Top">
    <StackPanel>
      <Button Margin="3">One</Button>
      <Button Margin="3">Two</Button>
      <Button Margin="3">Three</Button>
    </StackPanel>
  </Border>
</Window>

   
    
    
    
    
     


Set Border's BorderBrush to ImageBrush

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.UsingImageBrush.TilingExample" >

  <Grid Margin="20">
    <Border Grid.Row="6" Grid.Column="4" BorderThickness="20" Width="200"
     HorizontalAlignment="Left">
      <Border.BorderBrush>
        <ImageBrush ImageSource="c:image.jpg" Viewport="-0.1,-0.1,1.5,1.5" />
      </Border.BorderBrush>
      <DockPanel>
        <TextBlock DockPanel.Dock="Top" TextWrapping="Wrap" Margin="10">This DockPanel has a border painted with an ImageBrush.</TextBlock>
      </DockPanel>
    </Border>

  </Grid>
</Page>

   
    
    
    
    
     


Set Border Margin, BorderThickness, BorderBrush, Width and Height

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="WPF" Height="160" Width="300">
    <Grid>
        <Border Margin="8" 
                BorderThickness="1"
                BorderBrush="Black"
                Width="160" 
                Height="60">
            <TextBlock Foreground="DarkGray" 
                       VerticalAlignment="Center" 
                       HorizontalAlignment="Center"
                       ToolTip="This is a custom tooltip"
                       Text="Mouse Over for tooltip"/>
        </Border>
    </Grid>
    
</Window>

   
    
    
    
    
     


Adding border to TextBlock with Border

image_pdfimage_print


   
     
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      HorizontalAlignment="Center" VerticalAlignment="Center"
      TextElement.FontFamily="Palatino Linotype"
      FontSize="40">

    <Border BorderBrush="Black" BorderThickness="2" Width="213">
        <TextBlock TextTrimming="None" Text="Too much text." />
    </Border>

</Window>

   
    
    
    
    
     


Border with LinearGradientBrush

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">
  
    <Border Margin="0,10,0,10">
      <Border.Background>
        <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
          <LinearGradientBrush.GradientStops>
            <GradientStop Offset="0.0" Color="#CCCCFF" />
            <GradientStop Offset="1.0" Color="White" />
          </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>
      </Border.Background>
    
    <TextBlock Margin="10" MaxWidth="700">
asdf
    </TextBlock>
    </Border>

</Window>

   
    
    
    
     


Set border thickness

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="WPF" Height="300" Width="300">
    <UniformGrid>
        <UniformGrid.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="FontSize" Value="14" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
        </UniformGrid.Resources>

        <Border BorderBrush="Black" BorderThickness="4px, 4px, 0px, 0px" 
                Margin="10">
            <TextBlock Text="A half border" />
        </Border>

    </UniformGrid>
</Window>

   
    
    
    
    
     


Set border margin

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="WPF" Height="300" Width="300">
    <UniformGrid>
        <UniformGrid.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="FontSize" Value="14" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
        </UniformGrid.Resources>

        <Border CornerRadius="0, 5, 30, 90" Background="LightGray" 
                BorderBrush="LightGray" BorderThickness="2px, 5px, 2px, 5px" 
                Margin="10">
            <TextBlock Text="A wonky border" />
        </Border>

    </UniformGrid>
</Window>