Simple Layout with the StackPanel
The StackPanel is one of the simplest layout containers. It simply stacks its children in a single row or column.
For example, consider this window, which contains a stack of three buttons:
<Window x:Class="Layout.SimpleStack" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Layout" Height="223" Width="354" > <StackPanel> <Label>A Button Stack</Label> <Button>Button 1</Button> <Button>Button 2</Button> <Button>Button 3</Button> <Button>Button 4</Button> </StackPanel> </Window>
Figure 4-2 shows the window that results.
The StackPanel in action
USING THE STACKPANEL IN VISUAL STUDIOIt's relatively easy to create this example using ... |
Get Pro WPF in C# 2008: Windows Presentation Foundation with .NET 3.5, Second Edition 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.