StackPanel stretches its child elements by default, but you can take control of how it will stretch. On a vertically oriented StackPanel, you can assign the HorizontalAlignment property of the child elements to Left, Center, Right, or Stretch, as shown in the following code:
<StackPanel Orientation="Vertical"> <Button Content="Button (Left)" Margin="4" HorizontalAlignment="Left"/> <Button Content="Button (Center)" Margin="4" HorizontalAlignment="Center"/> <Button Content="Button (Right)" Margin="4" HorizontalAlignment="Right"/> <Button Content="Button (Stretch)" Margin="4" HorizontalAlignment="Stretch" /> </StackPanel>
The preceding code example will give you the following output:
Similarly, you can assign the VerticalAlignment...