Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Using the StackPanel layout panel

Using the StackPanel layout panel

Visual Studio 2012

A StackPanel layout panel allows you to stack objects in an assigned direction. Based on the properties that you define within a StackPanel layout panel, content can flow both vertically (by default) and horizontally. A StackPanel layout panel is predominantly used within list controls, such as within a ListBox control or within the pop-up list in a ComboBox control. Any object that you create or draw within a StackPanel layout panel will be added automatically as the last child object in the stacking order of the objects in the panel. As you add more child objects, you will see that the StackPanel layout panel will clip (or hide) those objects that do not fit.

  • Orientation   By default, the objects within a StackPanel layout panel are stacked vertically, but you can also stack them horizontally.

  • Nested Panels   You can use a nested layout panel (in other words, you can use a layout panel as a child object) to contain the side-by-side objects. The nested panel stacks in exactly the same way as any other child objects contained within the parent StackPanel layout panel.

Add a StackPanel layout panel to a document by selecting StackPanel ec58af86-cc2a-4e1f-91c0-883c5406fdfb from the Assets panel 0d8b8d29-1af9-418f-8741-be3097d76eab or from the layout container button in the Tools panel, and then dragging on the artboard. The following XAML code is added to your project:

<Grid x:Name="LayoutRoot">
   <StackPanel HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100"/>
</Grid>

For more information about working with the StackPanel layout panel, see Change the stacking order and Change the stack orientation.

Objects in a stack panel set to vertical orientation

a85a7b57-b0a8-495e-b985-f0291e41d093
Show:
© 2015 Microsoft