#435 – Use Border Element to Draw Border Around Elements
November 22, 2011 Leave a comment
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.