In today’s lesson we will be learning about a Layout control named the StackPanel control. What the StackPanel control does is organize a number of controls in a row or column. You also have the ability to change the Horizontal and Vertical Alignment as well so positioning can be set to your liking.

The only con for this type of layout control is that you can only have one control per column or row, depending on the Orientation you set the StackPanel control to.

To begin, let’s create a new project for today’s example. Once we have done so we can add a StackPanel control to our XAML file from the ToolBox.

Now we can add three Button controls to demonstrate the how the controls are organized.

We can now go ahead and edit the properties of the Buttons for Horizontal Alignment within the StackPanel. What this does is position the Buttons similar to how you would do in a web application using CSS.

We also have the option to change the Orientation of the StackPanel Control to Horizontal, instead of the default setting of Vertical, like so:

Another benefit of the StackPanel is that it can be set up similar to Panel controls in web development to contain small groups of controls that can be moved together as a whole, as multiple StackPanels can be placed on the same display at one time.

And there you have it; we have just covered a few of the different ways to use the StackPanel control in Silverlight for the Windows Phone 7 platform using Microsoft Visual Studio 2010. If you have any other questions or concerns and have not yet downloaded the source code for this project, I strongly suggest doing so. Seeing it in its entirety can help clear up many of your questions. Thank you for your time and I hope this has been helpful, take care.

Download Source Files