Export (0) Print
Expand All

Using the StackPanel layout panel

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 Cc294551.ec58af86-cc2a-4e1f-91c0-883c5406fdfb(en-us,Expression.40).png from the Assets panel Cc294551.0d8b8d29-1af9-418f-8741-be3097d76eab(en-us,Expression.40).png 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

Cc294551.a85a7b57-b0a8-495e-b985-f0291e41d093(en-us,Expression.40).png

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.
Show:
© 2014 Microsoft