Portland Code Camp 2010 was last Saturday and I had the pleasure of being able to present a few findings. Jesse Johnston and I teamed up to go over a few of the things we’ve learned about Windows Phone 7 development. This was a talk about the state of the art today. However, I expect the landscape to change quickly as development tools are being continually enhanced the closer we get to the public release of phones.
The slides and links to source code from the talk are available here.
Here are my notes about the demo application and a few of the Windows Phone 7 topics I talked about.
Design Guidance
Controls - Panorama and Pivot - And Some Demo App Organization
MVVM Light - http://www.galasoft.ch/mvvm/getstarted/
This demo application uses a code pattern known as Model View View Model (MVVM). Most of the community is in full support of using this pattern. Laurent Bugnion is the author of this framework for using the pattern and he spoke at MIX 2010 about it. The framework provides a set of project and item templates to install. As well as some binaries that contain some important base classes.
This demo application uses MVVM Light and it has a couple of enhancements to it. In MVVM, essentially, there is little or no code behind in a page, only XAML. A DataContext is applied to the View and that is the ViewModel. The ViewModel contains everything (event handlers, methods, properties) that the View needs to bind to. And the ViewModel handles construction and management of data of one or more Models. You can take a closer look at MVVM Light and how it was used in the demo at the links above.
So, the demo application uses one version of something called the Panorama control. This is a control widely demoed at MIX and during all of the initial Windows Phone 7 launches. There is a similar control known as the Pivot control. The main difference between Panorama and Pivot controls is the way that content does or does not run over into another section horizontally. In other words, there is a fixed width for each section that fits in the screen for a Pivot control. A Panorama control can have a detail section wider than one width of the phone screen.
There are several different implementations for the Panorama control. It is assumed by many developers that a version of the control will be released from Microsoft. I hope this is true. Until then, you can choose from some good alternatives.
We are using the CodePlex project version for the demo since it is maintainable and easy to use. Also, orientationchanges are supported a bit better than the others. If you want to get into styling the templates for the control, source code is provided. Because this control is templated you can get away with copying the themes file (generic.xaml) from source code. Then you can customize it in a phone project. For example, if you wanted to set the Title section of the Panorama control to include an Image and some text, you could copy a template from the control source code into your phone project and make customizations to it from there.
One thing that is really nice in the phone control set is that anything using a ScrollViewer, like a ListBox, automatically has panning and flick gesturing applied to it. Without writing any additional code. There is a nice inertia animation that you get out of the box.
Application Bar
UX guidance recommends that instead of placing buttons for common tasks on each page, you can use the Application Bar. There is a limit of 4 button items in the Application Bar. The menu items, which are visible when the user clicks an ellipse symbol, are automatically put in a ListBox control.
As Laurent points out in his post about the MVVM Light framework, the ApplicationBar is a control but the ApplicationBarItems are not. This means that without a little help, you will be adding event handler code in the code behind of your view. Fortunately, Jesse found a nice work around to the issue and it is available in the demo app source.
A little tip is that button icons will rotate to match the phone's orientation. But only if the orientation is supported on the page. So, the SupportedOrientations property needs to be set to PortraitOrLandscape in order to see the icons rotate with the page.
Orientation
So for orientation I mentioned the SupportedOrientations property as it relates to icons. When you set the property to PortraitOrLandscape, it will re-orient the controls on the page automatically. The user interface that you designed for a Portrait layout will not always work the same or be a desirable layout in a Landscape orientation. The phone page object has OrientationChanged and OrientationChanging events that you can use to change the states or layout of your UI. And in there you can respond to the value by either setting up a visual state change, or manually setting some values on the view's visual elements.
Emulator(s)
The Emulator is a virtual machine that runs an image of the Windows Phone 7 OS. It is exactly the same experience that the developer will see on a real phone device. The general idea is that a device is not required to do all of the development and testing work for a phone application. Instead only hardware performance on a real phone device is worthwhile to test. Until developers have devices to target software to, the emulator can be used with a high degree of confidence that the experience will be the same.
The Emulator is based on part on the capabilities of your host PC. It is worth noting that if your video card does not have GPU acceleration, you might see a performance hit running the emulator. Networking is enabled by default and is based on the network on the host PC. So, if you are behind a firewall and have a proxy server, the phone emulator will also be behind those things.
To allow developers to start building Windows Phone 7 applications quickly, Microsoft released the first version of the phone emulator at MIX this year. The first version was a "mini-UI" that only had IE7+ in it. They weren't ready to show the rest of the applications and operating system so they weren't on the emulator initially.
The next emulator appeared first on the xda-developers site. Meaning, some folks took apart an existing ROM and unlocked some features. It was build 6077 and was also known as the MIX 10 WP7 ROM. That ROM was used for demos at MIX and included unlocked Zune Marketplace functionality as well as a lot of other apps. Such as the phone Calendar and XBox Live demo application.
Close to April 30th, another unlocked ROM appeared with version 6177. As of this writing, it is the latest version of the WP7 emulator that you can use to develop software on. It includes the unlocked version of Office, a Zune hub, a Pictures hub, and again the XBox Live hub.
There are two important reasons to use this latest ROM for developing phone apps. (Read more from Justin Angel about this at his blog post here). First, this ROM has a plethora of existing applications to better understand the desired user experiences. The Office application shows off a nice Panorama control. The People application shows off a Pivot control implementations.
The second and perhaps more important reason from a development point of view is that more capabilities and features are enabled. A large majority of tasks and choosers are enabled. For example, the EmailChooserTask allows an application to start up a contact list so the user can select an existing email contact. There is a full list of tasks and choosers to start using here: http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks(VS.92).aspx
Finally, there is a lot of nice system information to be found in the latest emulator. Find the application SystemInfo in the emulator and you will see a Task Manager. When you click and hold on a process in the list, you can get to a nice Pivot control that shows a ton of information. A details dashboard, threads, heaps, allocs, and modules.
There is a second screen within SystemInfo that you can get to by clicking the arrow on the upper right corner. Go ahead and click on the "install shell chrome". It will pop up a warning and confirming it will show a small arrow button in the top right corner of the emulator screen area. Now from any running application on the phone you can turn on a few overlays like CPU, and memory monitors. You can drag these around the screen so they are sort of out of the way. There are a few more overlay items like this Spinner, a Free Memory graph, and Frames Per Second.
Summary
Portland Code Camp was a great event this year and it was fun to be able to speak at it. There are some great resources for developing applications for Windows Phone 7. The demo application we included for the talk hopefully goes a little beyond the typical “hello world” application. You should be able to use MVVM Light and a few other gems in there to get started writing your own phone applications.