Microsoft 9GD00001 Computer Accessories User Manual


 
Chapter 8: Building Desktop Applications with WPF 223
select the grid, which is added by default to a new project, and delete the Grid. Figure 8-4
shows a StackPanel that contains multiple button controls.
In Figure 8-4, it doesn’t matter where you try to lay the buttons—the StackPanel will
always lay them out one after the other. In addition to vertical layout, the StackPanel can
lay out controls horizontally. Just change the Orientation property, shown in the Properties
window in Figure 8-4, to Horizontal. Next, you’ll learn how to dock controls to the sides
of a container.
DockPanel Layout
You’ve seen how VS allows you to dock windows within the borders of the application.
This helps you organize your screen so that you can use many tools at one time. You can
lay out your controls the same way with the DockPanel control.
Get started by dragging and dropping a DockPanel control from the T
oolbox to the
Window in the design surface. You might want to delete the default Grid first. Also, the
DockPanel initializes with a Height and a Width, which you’ll probably want to remove
by selecting the DockPanel, opening the Properties window, and clearing the Height and
Figure 8-4 Using a StackPanel layout