Using StackPanel to define the stacked layout

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

If you don't specify any orientation, it will be automatically set as a vertical StackPanel. 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"/> <TextBlock Text="Stack 3"/> <TextBlock Text="Stack 4"/> </StackPanel> <!-- Vertical StackPanel --> <StackPanel Orientation="Vertical"> <TextBlock Text="Stack 1"/> <TextBlock Text="Stack 2"/> <TextBlock Text="Stack 3"/> <TextBlock Text="Stack 4"/> </StackPanel>

While using StackPanel, do note that the content does not resize when you resize the panel.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.86.155