WP7 Development Tip of the Day: Silverlight Toolkit: WrapPanel

by brad 10. November 2010 06:00

Today’s tip focuses on the WrapPanel that’s available in the Silverlight Toolkit for Windows Phone.  If you’re not familiar with the Toolkit, check out the introductory post.

About the WrapPanel

The WrapPanel has always been a popular control in both Silverlight and WPF.  Originally shipping with WPF, the WrapPanel lets you drop a series of controls into a container that will arrange them as if they were words on a page …. left-to-right and then top-to-bottom. Or think of Windows Explorer arranging icons. It’s a natural extension of the StackPanel.

The WrapPanel has been part of the non-Phone Silverlight Toolkit since the very beginning, and could be used in phone projects by adding the non-Phone Toolkit references to your project. 

Now that the WrapPanel is part of the phone-specific toolkit, things are even easier.  Same basic steps, but without the extra baggage of the non-Phone toolkit.

Using the WrapPanel

To use the WrapPanel, first add a reference to Microsoft.Phone.Controls.Toolkit.dll, which is installed with the toolkit.

Next, add a reference to the assembly in your page XAML

   1: xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;
   2:                assembly=Microsoft.Phone.Controls.Toolkit" 

The XAML

Since the WrapPanel is a container, the XAML is pretty simple.  Here’s a wrap panel with six obnoxiously colored buttons in it. 

   1: <toolkit:WrapPanel>
   2:     <Button Content="One" BorderBrush="Aqua" />
   3:     <Button Content="Two" BorderBrush="CadetBlue" />
   4:     <Button Content="Three" BorderBrush="DarkMagenta" />
   5:     <Button Content="Four" BorderBrush="Fuchsia" />
   6:     <Button Content="Five" BorderBrush="LightBlue" />
   7:     <Button Content="Six" BorderBrush="Orange" />
   8: </toolkit:WrapPanel>

This creates the standard left-to-right, top-to-bottom wrap panel.

CropperCapture[4]

You can also set the Orientation to “Vertical” to create a top-to-bottom, left-to-right wrap panel.

   1: <toolkit:WrapPanel Orientation="Vertical" Height="400">
   2:     <Button Content="One" BorderBrush="Aqua" />
   3:     <Button Content="Two" BorderBrush="CadetBlue" />
   4:     <Button Content="Three" BorderBrush="DarkMagenta" />
   5:     <Button Content="Four" BorderBrush="Fuchsia" />
   6:     <Button Content="Five" BorderBrush="LightBlue" />
   7:     <Button Content="Six" BorderBrush="Orange" />
   8: </toolkit:WrapPanel>
CropperCapture[5]

Other Resources

More Tips

Tags:

Windows Phone | WP7 Tip of the Day

Comments

11/10/2010 3:30:20 PM #

trackback

WP7 Development Tip of the Day: Silverlight Toolkit for Windows Phone

WP7 Development Tip of the Day: Silverlight Toolkit for Windows Phone

code badger

11/13/2010 4:14:50 PM #

pingback

Pingback from topsy.com

Twitter Trackbacks for
        
        WP7 Development Tip of the Day: Silverlight Toolkit: WrapPanel
        [codebadger.com]
        on Topsy.com

topsy.com

Comments are closed

About Brad

Brad Tutterow lives in Illinois and works in Missouri. He has 12 years of experience developing web sites and Windows applications using a variety of technologies and is most excited currently about Silverlight, Windows Phone 7, Halo Reach, and Visual Studio 2010.