#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.

About these ads

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 347 other followers

%d bloggers like this: