Skip to content

Latest commit

 

History

History
68 lines (44 loc) · 3.25 KB

File metadata and controls

68 lines (44 loc) · 3.25 KB
-api-id -api-type
T:Microsoft.UI.Xaml.Controls.StackPanel
winrt class

Microsoft.UI.Xaml.Controls.StackPanel

-description

Arranges child elements into a single line that can be oriented horizontally or vertically.

-xaml-syntax

<StackPanel .../>
-or-
<StackPanel ...>
  oneOrMoreChildren
</StackPanel>

-remarks

Tip

For more info, design guidance, and code examples, see Layout panels.

StackPanel is a layout panel that arranges child elements into a single line that can be oriented horizontally or vertically.

Stack panel layout control

By default, StackPanel stacks items vertically from top to bottom in the order they are declared. You can set the Orientation property to Horizontal to stack items from left to right.

You can insert items into a StackPanel at a specific location using the InsertAt method in code-behind.

Border properties

StackPanel defines border properties that let you draw a border around the StackPanel without using an additional Border element. The properties are StackPanel.BorderBrush, StackPanel.BorderThickness, StackPanel.CornerRadius, and StackPanel.Padding.

<StackPanel BorderBrush="Red" BorderThickness="2" CornerRadius="10" Padding="12">
    <TextBlock Text="Hello World!"/>
</StackPanel>

-examples

Tip

For more info, design guidance, and code examples, see Layout panels.

[!div class="nextstepaction"] Open the WinUI 3 Gallery app and see the StackPanel in action

The WinUI 3 Gallery app includes interactive examples of most WinUI 3 controls, features, and functionality. Get the app from the Microsoft Store or get the source code on GitHub.

The following example shows how to create a StackPanel of items.

[!code-xamlLayoutOvwStackPanel_1]

[!code-xaml02]

[!code-csharp01]

-see-also

Panel, IScrollSnapPointsInfo, Define layouts, Alignment, margin, and padding, Canvas, Grid, ItemsStackPanel, VariableSizedWrapGrid, VirtualizingStackPanel, Controls list