Border
The Border control decorates a child with a border and background. It can also be used to display rounded corners by setting the CornerRadius property.
An example of a border with a red background, 2 pixel black border, 3 pixel corner radius and a 4 pixel padding around its content:
1
<Border Background="Red"
2
BorderBrush="Black"
3
BorderThickness="2"
4
CornerRadius="3"
5
Padding="4">
6
<StackPanel>
7
<Button>Button 1</Button>
8
<Button>Button 2</Button>
9
</StackPanel>
10
</Border>
Copied!

Box Shadows

A border can display a box shadow around it by setting the BoxShadow property.
Specify a single box shadow using:
    An optional inset keyword
    Two, three, or four length values.
      If only two values are given, they are interpreted as offset-x offset-y values.
      If a third value is given, it is interpreted as a blur-radius.
      If a fourth value is given, it is interpreted as a spread-radius.
    A color value.
To specify multiple shadows, provide a comma-separated list of shadows.

Values

    inset: If not specified (default), the shadow is assumed to be a drop shadow (as if the box were raised above the content). The presence of the inset keyword changes the shadow to one inside the frame (as if the content was depressed inside the box). Inset shadows are drawn inside the border (even transparent ones), above the background, but below content
    offset-x offset-y: offset-x specifies the horizontal distance. Negative values place the shadow to the left of the element. offset-y specifies the vertical distance. Negative values place the shadow above the element. If both values are 0, the shadow is placed behind the element (and may generate a blur effect if blur-radius and/or spread-radius is set)
    blur-radius: The larger this value, the bigger the blur, so the shadow becomes bigger and lighter. Negative values are not allowed. If not specified, it will be 0 (the shadow's edge is sharp)
    spread-radius: Positive values will cause the shadow to expand and grow bigger, negative values will cause the shadow to shrink. If not specified, it will be 0 (the shadow will be the same size as the element).
    color: The color of the shadow using a color name (such as red) or a # hexadecimal color value
1
<Border Background="Red"
2
BorderBrush="Black"
3
BorderThickness="2"
4
CornerRadius="3"
5
Padding="4"
6
BoxShadow="5 5 10 2 Blue">
7
<StackPanel>
8
<Button>Button 1</Button>
9
<Button>Button 2</Button>
10
</StackPanel>
11
</Border>
Copied!

Common Properties

Property
Description
Background
A Brush describing the color of the control's background
BorderBrush
A Brush describing the color of the control's border stroke
BorderThickness
The thickness of the control's border stroke
Child
The child control to decorate
CornerRadius
The radius of the border's rounded corners

Pseudoclasses

None

API Reference

​Border​

Source code

​Border.cs​
Last modified 2mo ago