StackPanel
Introduction
StackPanel is a container used to for controls which should stack vertically or horizontally, and which supports wrapping. StackPanels do not include any visual so they are always invisible.
Code Example - Adding Buttons to a StackPanel
The following code shows how to add Button instances to a StackPanel. Notice that each button is automatically stacked vertically.
Stack Panel Sizing
By defaut StackPanels contain a Visual with the following properties:
WidthUnits = Absolute
HeightUnits = RelativeToChildren
This means that as more children are added to a StackPanel, the StackPanel grows vertically.
The following code creates a main StackPanel with two internal StackPanels. Each internal StackPanel contains a Button which can be used to add labels to the respective internal StackPanel.
Orientation
WidthUnits and HeightUnits are not changed when changing Orientation. If you want the StackPanel instance to grow horizontally when changing Orientation to Horizontal, you need to modify the WidthUnits and HeightUnits.
Last updated
Was this helpful?