StackPanel.Orientation Property

July 28, 2014

Gets or sets the dimension by which child elements are stacked.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public Orientation Orientation { get; set; }
<StackPanel Orientation="Horizontal"/>
-or-
<StackPanel Orientation="Vertical"/>

Property Value

Type: System.Windows.Controls.Orientation
One of the enumeration values that specifies the orientation of child elements. The default is Vertical.

Dependency property identifier field: OrientationProperty

The following example creates a horizontal list of items by setting the Orientation property to Horizontal.


<StackPanel Orientation="Horizontal" Margin="20">
    <Rectangle Fill="Red" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Blue" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Green" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Purple" Width="50" Height="50" Margin="5" />
</StackPanel>


The preceding example produces output that is similar to the following illustration.

basic horizontal stack panel

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft