StackPanel Control

The StackPanel is a layout control that arranges child elements in a single line, either horizontally or vertically. It's a fundamental building block for creating user interfaces in Windows applications using the Windows UI Library (WinUI).

Key Properties

Basic Usage

Here's a simple example of a vertical StackPanel containing a few elements:

XAML Example

<StackPanel Orientation="Vertical" Spacing="10">
    <Button Content="Button 1" />
    <TextBlock Text="Some Text" />
    <TextBox PlaceholderText="Enter something" />
</StackPanel>

Horizontal Orientation

You can easily switch the orientation to horizontal:

XAML Example (Horizontal)

<StackPanel Orientation="Horizontal" Spacing="15">
    <Button Content="First" />
    <TextBlock Text="Second" />
    <Image Source="ms-appx:///Assets/icon.png" Width="30" Height="30" />
</StackPanel>

Demonstration

Live Demo

Item B
Item E

When to Use StackPanel

StackPanel is ideal for:

For more complex layouts that require precise alignment, sizing, and arrangement of elements in both rows and columns, consider using the Grid control.