XAML Border

The XAML <Border> element represents a border in Windows app. Code example in this tutorial shows how to apply a border to WPF controls using XAML and C#.

XAML Border Code Example

XAML Border 
 
The <Border> element in XAML represents a border that can be applied to an XAML control. The Border class in C# is used to create and apply borders dynamically. The code sample in this article shows how to create a border around XAML elements.
 
To apply a border to a XAML element, you can place the element within a Border element, 
 
The BorderThickness and BorderBrush are two main properties of a Border The BorderBrush property represents the brush that is used to draw the border. The BorderThickness property represents the thickness of the border.

The CornerRadius property represents the degree to which the corners of a Border are rounded.

The following code snippet creates a Border element and sets its properties.
  1. <Border  
  2.    BorderThickness="5"  
  3.    BorderBrush="Green"  
  4.    CornerRadius="10"  
  5.    Background="LightGray"  
  6.    HorizontalAlignment="Left"  
  7.    VerticalAlignment="Top"  
  8.    Width="270"  
  9.    Height="250" /> 

The code snippet in Listing 1 creates a border around a Canvas element and sets its properties.

The output looks like in Figure 1 where all the child controls are wrapped horizontally.

  1. <Border  
  2.    BorderThickness="5"  
  3.    BorderBrush="Green"  
  4.    CornerRadius="10"  
  5.    Background="LightGray"  
  6.    HorizontalAlignment="Left"  
  7.    VerticalAlignment="Top"  
  8.    Width="270"  
  9.    Height="250">  
  10.   
  11.    <Canvas Background="LightCyan" >  
  12.       <Rectangle  
  13.          Canvas.Left="30" Canvas.Top="20"  
  14.          Height="200" Width="200"  
  15.          Stroke="Black" StrokeThickness="10" Fill="Red" />  
  16.    </Canvas>  
  17. </Border> 

Listing 1

The complete article has moved here: Border in WPF