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 O’Reilly online learning.
O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.