In this article I will discuss about the WrapPanel crontrol in Window Phone 7. WrapPanel comes along with Silverlight Windows Phone Toolkit. WrapPanel become very handy when you have to create series of tiles whether it is vertical or horizontal. It wouldn't be easy to create a series of tile without WrapPanel.

Now, run the application, you will get all the rectangles placed inside WrapPanel like below. The Orientation of WrapPanel can be changed using Orientation Property. E.g. Orientation="Vertical"

Orientation - Horizontal Orientation - Vertical

Step 5: By default flow direction is LeftToRight in WrapPanel, the flow direction can be changed to RightToLeft using FlowDirection property.

FlowDirection

="LeftToRight" orlowDirection="RightToLeft"

Change the FlowDirection property and run the application. You will notice that WrapPanel placed the rectangles from right to left like shown in below image.

Step 6: WrapPanel can be used in advanced scenario like it can be used with ListBox, ListPicker and other ItemControls. Let's use WrapPanel in ListBox.

Comment or delete WrapPanel code which we had placed inside the ContentPanel of MainPage.xaml in Step 4.

Put below code inside the ContentPanel of MainPage.xaml. It has a ListBox with WrapPanel inside ItemsPanelTemplate. ItemTemplate will have Button to place inside WrapPanel. The color of the button will be Green by default. I have attached click handler, the color of button will be changed to Red when it is clicked.