WPF Border Control


The Border control is a Decorator control that you can use to draw a border, a background, or even both, around another element. Since the WPF panels don’t support drawing a border around its edges, the Border control can help you achieve that. You could surround a Panel with a Border.

Below is the XAML code for this project.

<Window x:Class="BorderControl.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:BorderControl"
        mc:Ignorable="d"
        WindowStartupLocation="CenterScreen"
        Title="BorderControl" Height="250" Width="400">
    <Grid>
        <Border Background="Azure" BorderBrush="Gray" BorderThickness="2">
            <StackPanel Margin="10">
                <Button>Button 1</Button>
                <Button Margin="0,10">Button 2</Button>
                <Button>Button 3</Button>
            </StackPanel>
        </Border>
    </Grid>
</Window>

In the next section we will do a little more.