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.



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


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.



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


No comments: