4. Panely

4.3. StackPanel

StackPanel je obdobný jako WrapPanel, ale s jedním rozdílem: Místo toho, aby byly kontrolky řazeny za sebou, jsou řazeny pod sebou.

<Window x:Class="WpfTutorialSamples.Panels.StackPanel"

         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

         Title="StackPanel" Height="160" Width="300">

     <StackPanel>

          <Button>Button 1</Button>

          <Button>Button 2</Button>

          <Button>Button 3</Button>

          <Button>Button 4</Button>

          <Button>Button 5</Button>

          <Button>Button 6</Button>

     </StackPanel>

</Window>

image

Jednoduchým trikem je možné ze StackPanelu vyrobit WrapPanel:

<StackPanel Orientation="Horizontal">

image

Standartní hodnota vlastnosti HorizontalAlignment je Stretch. Podívejme se, co se stane, když ji budeme měnit v rámci StackPanelu:

<Window x:Class="WpfTutorialSamples.Panels.StackPanel"

         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

         Title="StackPanel" Height="160" Width="300">

     <StackPanel Orientation="Vertical">

          <Button HorizontalAlignment="Left">Button 1</Button>

          <Button HorizontalAlignment="Center">Button 2</Button>

          <Button HorizontalAlignment="Right">Button 3</Button>

          <Button HorizontalAlignment="Right">Button 4</Button>

          <Button HorizontalAlignment="Center">Button 5</Button>

          <Button HorizontalAlignment="Left">Button 6</Button>

     </StackPanel>

</Window>