Like .Net 2.0, WPF provides a set of layouts that allows the users to easily place the controls in to it. Lets look in to it, one by one comparing with the net 2.0 version of it.
StackLayout
This was called as FlowLayout in .net 2. Controls that are added in to this layout will be automatically aligned either in a vertical or in a horizontal fashion. This alignment depends on the value of Orientaion property. The value can either be Vertical or Horizontal.
Vertical Orientation
<StackPanel Orientation="Vertical"> <Button Content="Button1" /> <Button Content="Button2" /> </StackPanel>
Horizontal Orientation
<StackPanel Orientation="Horizontal"> <Button Content="Button1" /> <Button Content="Button2" /> </StackPanel>
If you notice the screenshots, you will find that the width of the button is automatically controlled by the WPF framework. Thats why the buttons are stretched. But if you wanna control the width, you can play with the HorizontalAlignment property of the control. The default alignment is Stretched. Specifying a width for the control along with the HorizontalAlignment property allows you to have total control on the size and location of the control.
<StackPanel Orientation="Vertical"> <Button Content="Button1" /> <Button Content="Button2" HorizontalAlignment="Left" /> <Button Content="Button3" HorizontalAlignment="Right" /> <Button Content="Button4" HorizontalAlignment="Center" /> <Button Content="Button5" HorizontalAlignment="Stretch" /> </StackPanel>
We can see this layout in action in loads of places. For example, the search tool that comes with windows has employed this layout.
Although this layout lets the us relax on alignments, we cannot place two controls parallel to each other (this layout is not intented to do so. we have another layout for this, GridLayout). Also this layout cannot wrap controls when the controls overflow (again this layout is not intented to do so. we have another layout for this, WrapPanel).



