Creating a border around panels and elements
Sometimes a simple decoration is required around some element or panel, such as a border. Luckily, the Border
element does just that to anything placed inside it.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create a simple border encompassing some text, to show most of the capabilities of Border
:
- Create a new WPF application named
CH03.BorderDemo
. - Open
MainWindow.xaml
. Replace the existingGrid
with aStackPanel
, and add aTextBlock
inside it, like the following markup shows:<StackPanel Margin="4"> <TextBlock Text="Hello from Center" FontSize="25" HorizontalAlignment="Center" /> </StackPanel>
- Running the application shows the text centered horizontally within the
StackPanel ...
Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.