#435 – Use Border Element to Draw Border Around Elements

You can easily draw a border around any control by nesting the element within a Border element in XAML.  The content property for the Border element is the Child property, which specifies the single child (an UIElement) contained with the border.  In XAML, you surround a control with a border by making it the child element of a Border element.

	<StackPanel>
		<Label Margin="10" Content="I'm free.."/>

        <Border Margin="10" BorderBrush="Black" BorderThickness="1">
            <Label Content="Don't Fence Me In"/>
        </Border>

        <Border Margin="10" BorderBrush="Black" BorderThickness="1">
            <StackPanel Orientation="Vertical" Margin="5">
                <Label Content="Staying within borders"/>
                <Button Content="Do It"/>
            </StackPanel>
        </Border>
	</StackPanel>

The BorderBrush and BorderThickness properties must both be specified.  The BorderBrush can be set to any brush, including solid or gradient brushes.  The BorderThickness property specifies the thickness of the border in device independent units.

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: