The Silverlight for Windows Phone Toolkit also includes the WrapPanel from the Silverlight Tookit. It is ideal for displaying content in wide PanoramaItems. The sample application that ships with the Silverlight for Windows Phone Toolkit source includes an example of this.
Since the subject has come up a few times, here’s how you do it:
- Give your PanaramaItem a horizontal orientation.
- Make the WrapPanel the child of the PanormaItem, and set its orientation to vertical.
Here’s a snippet that does just that:
It is a little confusing, because they both have Orientation properties. The PanoramaItem’s Orientation usage is like StackPanel’s—the Orientation refers to the direction that is measured at infinity, or in other words, that’s the direction that grows.
For WrapPanel, the semantics are different. The Orientation refers to the direction that the WrapPanel will fill first, in other words, it starts at the top left of the WrapPanel, then the next items fill in vertically until the first column is full.
This will look like this:
This may not be the look that you desire, however. You may wish rows to be filled first, but using as few columns as possible. The first thing that you might try is to change the Orientation of the WrapPanel to Horizontal, like this:
However, since this means that the WrapPanel will extend horizontally first (filling columns before rows) and the PanoramaItem lets its content extend horizontally indefinitely, the items all wind up in a single row. Time to break out some code.
Here’s how this example makes it so that the WrapPanel lays its items out horizontally, but taking as few columns as possible, so the look is nice and full. First, here’s what it looks like:
And here’s the guts of code-behind that does it:
In this case “Page” refers to the size of a single, vertically-oriented PanoramaItem. The attached project puts it all together.