Using StackPanel to define stacked layout

When you want to add elements in a stack fashion, either horizontally or vertically, you need to use the StackPanel. You need to specify the Orientation property to set whether it will be a horizontal stack panel or a vertical stack panel. The following figure demonstrates a horizontal and a vertical StackPanel:

If you don't specify any orientation, it will by default be set as a vertical stack panel. You can add multiple UI elements (controls or panels) as children to it:

    <!-- Horizontal StackPanel --> 
 <StackPanel Orientation="Horizontal"> <TextBlock Text="Stack 1"/> <TextBlock Text="Stack 2"/> ...

Get Mastering Visual Studio 2017 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.