StackPanel Layout

Vertical and horizontal stacking with Auto, Fixed, and Stretch sizing modes.

Overview

StackPanel arranges children sequentially along a main axis. Each child's size is controlled by StackPanel.SizeMode: Auto (preferred size), Fixed (explicit via StackPanel.FixedSize), or Stretch (fill remaining space equally).

<!-- Vertical stacking with mixed sizing -->
<StackPanel Orientation="Vertical">
    <TextBlock StackPanel.SizeMode="Fixed" StackPanel.FixedSize="1"
               Text="Fixed (1 row)" Background="#5F0000" />
    <TextBlock StackPanel.SizeMode="Fixed" StackPanel.FixedSize="2"
               Text="Fixed (2 rows)" Background="#00005F" />
    <TextBlock StackPanel.SizeMode="Stretch"
               Text="Stretch (fills remaining)" Background="#005F00" />
</StackPanel>

<!-- Horizontal stacking -->
<StackPanel Orientation="Horizontal">
    <TextBlock StackPanel.SizeMode="Fixed" StackPanel.FixedSize="15"
               Text="Fixed (15)" Background="#5F0000" />
    <TextBlock StackPanel.SizeMode="Auto" Text="Auto" Background="#00005F" />
    <TextBlock StackPanel.SizeMode="Stretch" Text="Stretch" Background="#005F00" />
</StackPanel>

Key Concepts