Thursday, August 7, 2008

How to use StackPanel Layout to arrange the items

StackPanel layout is another one of the widely used layouts but its behavior differs from other layouts. As the name speaks (Stack), it can stack child elements vertically or horizontally. Thus, you can find it neat and you do not need to adjust the position manually.

Stack Horizontally

One scenario that I can think of is Horizontal Menu Bar. Let’s look at the sample screenshot below for more feel of it.

clip_image002

XAML

<StackPanel Orientation="Horizontal" x:Name="stackPanel_Name" HorizontalAlignment="Right" Margin="0,5,0,0">

</StackPanel>











Stack Vertically









I used this quite often when I was creating shadow effect or reflection effect, and it works perfectly. Let’s look at the next screenshot.









clip_image004









XAML









<StackPanel Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">

</StackPanel>



















No comments: