10 August 2010
Apps in Windows Phone 7 make it easy to explore and experience information thanks to two similar navigation controls: panorama and pivot controls. We’ve made it easy for developers to build applications with these experiences by putting these Silverlight controls and associated tooling in the next release of the free developer tools (didn’t make the beta).
The controls are simple & easy to use, but I’ve seen enough rumbling on forums to know that developers are anxious to learn more about their capabilities.
9/16/2010 Update: These controls are now in the official Windows Phone developer tools (quick post by me, but you really want to download here).
In this post I’m going to introduce these controls and how they appear from a simple API & XAML perspective.
Panorama control inside of the Visual Studio design surface for the Windows Phone 7.
Since phones are just beginning to trickle out, if you’d like to see what the built-in applications look like, there’s some multimedia up at WindowsPhone7.com.
A panorama powers the people, music + videos, parts of Office, and more. Many of these have a large background and can be explored by panning and flicking between items. When you’re at one item, you will be able to see a little bit of the next item as well – a hint that there’s more to be explored. When you reach the far side of the panorama, you can keep going to wrap around to the beginning again, saving time.
A pivot control powers the e-mail and calendar pages, operating systems, etc. The top of the pivot control shows the headers for all the different items, and you can swipe and pan between the pages. Just like panorama, the control wraps infinitely – so when you reach the final item, instead of having to flick all the way back to the first item, you can just flick once more.
Both of the controls are lightweight enough to have great performance, while visually engaging and responsive to touch. Some features:
So let’s take a look at the two controls!
A visual depiction of the actual contents of the panorama control stretching beyond the physical size of the screen.
From the UI design and interaction guide for Windows Phone 7, the UX folks say:
Unlike standard applications that are designed to fit within the confines of the phone screen, these applications offer a unique way to view controls, data, and services by using a long horizontal canvas that extends beyond the confines of the screen.
…
Elements of a panoramic application serve as the starting point for more detailed experiences.
…
The background image is the lowest layer and is meant to give the panorama its rich magazine-like feel. Usually a full-bleed image, the background is potentially the most visual part of the application.
As all things in design go, what is not on the screen is as important as what is there: the control has a lot of empty space that helps keep the eye focused on the rich experience and data.
The Panorama control is placed on pages of your application and accepts a title and a background. Panorama sections are defined by PanoramaItem controls, and each has a header. The Title and Header are easiest to use when you’re just inserting text, but they also have associated HeaderTemplate and TitleTemplate dependency properties for data binding scenarios.
<controls:Panorama Title="my panorama"> <controls:Panorama.Background> <ImageBrush ImageSource="MyWidescreenBackground.jpg"/> </controls:Panorama.Background> <controls:PanoramaItem Header="first item"> <StackPanel> <TextBlock Text="This is a simple sample ..." Style="{StaticResource PhoneTextLargeStyle}" TextWrapping="Wrap"/> </StackPanel> </controls:PanoramaItem> <!-- insert other panorama items here in a real app --> </controls:Panorama>
The panorama allows for special sections that are wider than the screen. Built-in phone hubs often use this for sets of thumbnails, albums, and other displays. If this is the appropriate effect you want for a section, make sure that the PanoramaItem declares that intent by setting the orientation to horizontal. Here’s what the minimized XAML looks like:
<controls:PanoramaItem Orientation="Horizontal"> <!-- insert thumbnails and other goods here --> </controls:PanoramaItem>
The key application programming interface for the Panorama builds on top of ItemsControl: so you get the standard items control properties (Items, ItemsSource, etc.), but also additional properties for setting the header, title, and reacting to the currently selected items by the user.
The pivot control is a lot like the a tab control, but designed specifically for the phone and touch interaction. The entire pivot control (often the size of the screen and the root element on a page) can be panned, flicked, and manipulated – it’s not just about those headers (though those can be touched to navigate, too).
A simple pivot sample application running in the emulator. Notice that the phone’s theme in the emulator has been set to the light theme, and the control just works without the developer having to do anything.
From the design guidelines document:
A pivot control provides a quick way to manage views or pages within the application. This control can be used for filtering large datasets, viewing multiple data sets, or switching application views. The control places individual views horizontally next to each other, and manages the left and right navigation. Flicking or panning horizontally on the page cycles the pivot functionality.
<controls:Pivot Title="MY APPLICATION"> <controls:PivotItem Header="welcome"> <StackPanel Margin="20"> <TextBlock TextWrapping="Wrap" Text=" This is a simple sample ..." Style="{StaticResource PhoneTextLargeStyle}"> </TextBlock> </StackPanel> </controls:PivotItem> <!-- other pivot items --> </controls:Pivot>
Pivot item is a simple content control and does not have any other special properties.
The tools are fully integrated with the design tools: if you click on an item in XAML, that item will become the one active in the design surface. There’s also an easy way to add additional items, well-defined control property editing, and so this all makes it really easy to get started building immersive apps.
You can start off with an app powered by a panorama or pivot control: File > New Project has built-in templates for these apps.
When you want to add a new Windows Phone page to your app, you can also add one that’s all ready to go with either a panoramic experience or pivot control, too. Just go to the Project menu and select Add New Item:
This makes it really easy to build out applications as quick as you can click.
If you need to add either control to an existing app, in Blend you’ll find them in the Assets window, so they’re right where you’d expect to find them when you need ‘em.
Key properties are easily accessible in the property editor. In this screen capture, you can see how easy it is to change an item to Horizontal mode, or to change the Header property:
Integrated into the design surface you can also add extra items to the controls by right-clicking.
Visual Studio design surface
Expression Blend
The controls can be found in the Microsoft.Phone.Controls namespace of the Microsoft.Phone.Controls.dll assembly, installed with the official Windows Phone Developer Tools.
As we get closer to launch, I’m sure we will have a good list of caveats and suggestions for the controls. Here are a few things that I had in mind that I wanted to share ahead of time, in case you are designing your application experiences and pages today.
If you look at applications on the phone such as Mail, you’ll often see that the Pivot control is used to filter and sort data. So when you move to the “unread” pivot item, you have unread mail items; flicking your finger again, you’ll get to “flagged”, listing the messages that you have flagged.
You could easily have hundreds of items in a single pivot item.
If you want to enable scrolling, you must either use a scrolling control like ListBox, or add a ScrollViewer to the pivot or panorama item. Scrolling is not enabled by default. This helps ensure that items are always sized to the parent container like you’d expect in the Silverlight-powered layout system.
Here’s how to add a scroll viewer or list box to a pivot item. Note that you’ll only want to offer a vertical scrolling experience, since horizontal manipulations (pan or flick) are part of the navigation experience with these two controls.
<controls:Pivot Grid.Row="0" x:Name="Pivot1" Title="INBOX"> <controls:PivotItem Header="all"> <ListBox ItemTemplate="{StaticResource MyMailDataTemplate}" ItemsSource="{Binding Items}"> </ListBox> </controls:PivotItem> <controls:PivotItem Header="unread"> <ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <!-- Some large vertical list here --> </ScrollViewer> </controls:PivotItem> </controls:Pivot>
The example uses data binding to the data context, as well as custom-defined data templates from the application’s resources, so don’t just paste it into your app… but you get the idea I hope.
These controls do both derive from ItemsControl, but they do have subtle differences.
There are a number of alternative implementations of these controls out there, so for release, we’ll be working to blog guidance on migrating from one of those other experiences to these controls if you would like to. Note that the http://phone.codeplex.com/ controls *are not official* and you should probably consider using these instead now that the tools are public.
Jeff Wilcox is a Software Engineer at Microsoft in the Open Source Programs Office (OSPO), helping Microsoft engineers use, contribute to and release open source at scale.