Horizontal and vertical alignment in Silverlight

The example below shows the effects of all four HorizontalAlignment options and all four VerticalAlignment options. The HorizontalAlignment property accepts the Left, Center, Right, and Stretch values, whereas the VerticalAlignment property accepts the Top, Center, Bottom, and Stretch values.

<StackPanel Orientation="Horizontal">
<StackPanel Width="200" Background="LightGray">
<TextBox HorizontalAlignment="Left" />
<TextBox HorizontalAlignment="Center" />
<TextBox HorizontalAlignment="Right" />
<TextBox HorizontalAlignment="Stretch" />
</StackPanel>
<Canvas Width="20"></Canvas>
<StackPanel Width="200" Background="LightGray" Orientation="Horizontal">
<TextBox VerticalAlignment="Top" />
<TextBox VerticalAlignment="Center" />
<TextBox VerticalAlignment="Bottom" />
<TextBox VerticalAlignment="Stretch" />
</StackPanel>
</StackPanel>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.