An Introduction to the Windows Phone 7 Development Platform
On Sep 16th 2010, Microsoft made available the RTW (Released to Web) version of the development platform for Windows Phone 7. In some ways, for many of you, parts of this will be a re-introduction to technologies you already know or with which you have become familiar. This is great news because it means you can become productive very quickly, and that’s no mistake. If you are wondering whether this platform is going to be a success then consider that there are millions of developers out there with existing skills which they can already leverage to build applications for Windows Phone 7. Even for those who have never used tools like Visual Studio before, the barrier for entry is low because the basic toolset has been made available completely free of charge!
A Geo-location Application in Minutes
Want an application with the power of Bing Maps that shows you where you are?
Create a new Silverlight project in the free tools and drag a Map control onto the design surface of the provided page template…
Update the provided template code like this to add/update a pushpin once location is determined…
public partial class MainPage : PhoneApplicationPage
Pushpin pp = null;
GeoCoordinateWatcher watcher = null;
pp = new Pushpin();
pp.Content = "Here I am!";
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
pp.Location = e.Position.Location;
Press F5 to build and test in the free device emulator and double-click to zoom in or use your fingers if you have a touch-enabled display…
That’s powerful and productive! OK, I cheated a little. While this code works on an actual device, it will not position the pushpin in the platform emulator as the current tools release does not include location services emulation. However, a well-designed geo-location application will simulate location tracking events (as I did here – code not shown) unless of course, you plan on expensing a round-the-world trip in the name of software testing J
The Target Platform
When it comes to targeting the platform you have a very solid fix with Windows Phone 7. Developing for the platform is more akin to developing for Xbox than the WP7’s predecessor, Windows Mobile 6.5. While Microsoft has again partnered with device manufacturers to produce the phones, this time Microsoft has been very particular about the hardware requirements and provided much of the lower-level code to help bolster platform stability. If you develop for Windows Phone 7 today you can expect this of all devices your code runs on:
- A WVGA (480 x 800) display
- Capacitive 4-point multi-touch screen
- DirectX 9 hardware acceleration
- A-GPS, accelerometer, compass, light, proximity
- A 5MP+ digital camera
- Common hardware controls and buttons that include the Start, Search, and Back buttons
- Cellular networks and Wi-Fi radios
- 256 MB+ RAM
- 8 GB+ of flash storage
So now without having to worry about whether your software will run well on all devices, your biggest choice around the platform will be whether your application is going to be based on Silverlight or the XNA framework.
Both Silverlight and XNA-based solutions are built on a cut-down version of the .NET framework. Silverlight solutions are built using the controls + events methodology familiar to WinForms or WebForms developers. XNA solutions allow and require developers to create a low-level game loop which exercises detailed control of the drawing and animation of visuals along with the detecting of user interaction. One could generalize by saying that Silverlight is the choice for quick general application development including some gaming, while XNA is the choice for higher performing 2D and 3D games.
With these two frameworks at hand you can build stand-alone applications and utilities, or Internet-connected mobile line-of-business applications, remote control utilities along with a variety of games.
Not only does the WP7 platform support both, but both are supported on more than one platform. Let me explain that. If you develop an XNA game, there’s a good chance that 90% of your code - and I know people that can claim that number – can be re-used in an XNA build for Zune, Windows PC or Xbox Live Arcade. If you develop a Silverlight application for WP7, a good design may allow for many of your classes and perhaps even controls to be re-used on the desktop/web Silverlight platform in many browsers and platforms.
The Platform Tools
Go to the developer portal to get access to this neat little package of free tools in one installer:
- Visual Studio 2010 Express for Windows Phone
- XNA Game Studio 4.0
- Silverlight 4 Tools for Visual Studio
- Windows Phone Emulator Resources
- Microsoft Expression Blend for Windows Phone
If you have a version of Visual Studio 2010 Professional or above, then rather than installing as separate standalone Visual Studio products by default, the first two items above will create New Project templates in your existing installation. Likewise, if you have Expression Blend 4 installed, then that last Blend item will be added as a New Project template.
Developing with Silverlight enables you to leverage a well-known control + event paradigm. The Silverlight runtime and control set in Windows Phone 7 are akin to Silverlight 3 on the PC with a few omissions (such as TCP sockets) and Silverlight 4 additions (such as touch gesture APIs). A key difference from the desktop is that whereas Silverlight 3 applications run in the browser by default with the option of running out-of-browser from the Start menu, WP7 Silverlight applications launch directly from the Start screen without a browser wrapped around them. In fact the phone platform does not support Silverlight content inside web pages in the initial release.
The developer has several choices for the mechanics of building Silverlight applications, but XAML (as with desktop Silverlight and WPF) underpins the majority of solutions.
XAML or eXtensible Application Markup Language in Silverlight is form of XML that provides a powerful way of declaring a tree of UI controls, data bindings, resources behavours and even data. In most cases, you can declare UI in XML far more quickly than you can type code to programmatically instantiate the objects. You can in fact do either and may want to use code to react to UI events or dynamically create UI.
The tools provide IntelliSense support for XAML and code as well as a visual design surface that you can use to graphically build XAML by dragging and dropping controls from the toolbox window and then set properties in the Properties window.
Visual Studio showing the toolbox, graphical design surface, underlying XAML and properties window
The basic controls available in the phone’s Silverlight runtime are a subset of the ones for desktop Silverlight solution but are also styled automatically to fit with the phone’s overall UI style.
Silverlight uses a very powerful layout system for controls and panel controls which contain and arrange child controls. The phone runtime only comes with three panel controls: Grid, StackPanel & Canvas, however the architecture of controls is extremely powerful and extensible, allowing you to create your own controls and panels.
The deceptively small, yet powerful set of provided Silverlight controls for use on Windows Phone 7
Delightful UI Design
Get your hands on a real device or cruise to windowsphone7.com and you’ll see the smooth side-scrolling panorama experience allowing users to discover and move between data cleanly represented in textual or graphical form.
An example of the Panorama ‘viewport’ experience on Windows Phone 7
You can provide such an experience in a few minutes. Start up a New Project and pick the Windows Phone Panorama Application or Pivot Application and start customizing the template provided.
The included Panorama project template for Windows Phone 7
The default project templates also include examples of Model-View-ViewModel architecture upon which you can expand.
Speaking of MVVM and therefore the potential of less-code and more UI design, Expression Blend for Windows Phone provides the opportunity for you or a designer to add real flair to your application. Blend provides a productive UI design experience that focuses on the visuals, including visual editing of styles, data templates, layouts, animations, interactions and control states. While this is all possible in Visual Studio using XAML, an adept Blend user along with MVVM practices can greatly streamline the UX creation process.
The design-centric UI in Microsoft Blend for Windows Phone 7
No Test Device? No Problem
The free toolset includes a powerful emulator. It takes advantage of your DirectX 10.1 compatible GPU and hardware virtualization to provide a realistic experience. Start debugging and Visual Studio will start the emulator (if not already running in < 5 seconds in my case), deploy the application to the emulator (just a few more seconds) and start the application within a full debugging experience.
When it comes to testing the accelerometer, location services, touch gestures and gaming performance there’s no substitute for testing on a real device, though there’s a lot you can do with Reactive Extensions for .NET (to simulate device data) and a touch-enabled Windows PC (to simulate multi-touch gestures).
You can easily make use of the hardware included in all Windows Phone 7 devices using the platform APIs.
- The project templates include XAML for adding an application bar to your application.
A fully opened application bar in IE Mobile designable in about 10 lines of XAML plus handler code
- In just a few lines of code you can launch UI for the user to compose email, text messages & searches; choose/store email addresses & phone numbers from/to your contacts; connect directly to the marketplace; and setup up phone calls.
var task = new EmailComposeTask();
task.To = "firstname.lastname@example.org";
task.Subject = "Important News!";
task.Body = "Stuff you probably want to say";
Code to launch email compose UI
- You can respond to touch manipulation events that provide information on panning and zooming/pinching
- By creating the Accelerometer object and subscribing to events in a similar way to the location services in the opening example, you can track the position of each face of the device towards the ground for use in games or other natural UI interactions
Windows Phone 7 is a cloud-connected platform. The out-of-the-box phone experience allows users to connect multiple email accounts, various calendars, many picture sets and a number of social networks. Users purchase applications, music and games from cloud-hosted services. Notifications and updates come from the cloud (hosted on Microsoft’s Windows Azure Platform). The Windows Phone 7 platform builds upon many cloud-based services. If you have built any, especially for existing Silverlight applications, then your WP7 applications can likely use those along with the ones provided by Microsoft including Location services, Xbox Live, Windows Live, Map services, and Push Notification Services.
To maintain a fluid experience for users, all network requests must occur asynchronously; this prevents the UI thread for locking until a successful response or timeout occurs.
// Create generic or strong-bound service connection client
WebClient wc = new WebClient();
// Set up to receive event when request has completed
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
// Kick off asynchronous activity
wc.DownloadStringAsync(new Uri("<some URL>", UriKind.Absolute));
// Called when asynchronous network activity completed or error occurs
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
// Make sure there's no error, otherwise inform the user in some way
if (e.Error == null)
// If updating the UI when dispatch to the UI thread to avoid concurrency issues
// Do some activity like display the results
Example of initiating and completing networking activities asynchronously
The Isolated Storage APIs provide a means to store name-value settings or a whole file structure of text, XML or binary files exclusively under your applications access and control. This is a good store for:
- cached data
- data queued for sending
- local application settings
The rest could and really should be stored in the cloud using a variety of services such as Windows Azure and Windows Azure Storage.
When something changes in the cloud you’ll want to notify the application (if it’s running) by sending it raw data it can use, or the user (if it’s not) who can see notifications as popup ‘toast’ messages and/or changes to the tiles on the start screen. The Push Notification Service APIs are used to integrate on the phone and you’ll need to subscribe to a cloud service originating the notifications (that you mostly likely build). Windows Azure is a platform worth considering if you’ll need a highly scalable and reliable service.
The Gold Rush
The developer portal is not only the place to get the tools, but the place to submit and track applications you want to sell (including for free). Full details of the marketplace will be announced in October, but you can already sign up for an account and review the submission requirements.
For US$99 (varies by country, but is available in many countries!) you can submit as many charged-for applications as you like as well as up to 5 free applications (with additional free application submissions at $20 each). Qualifying students can join the DreamSpark program and get the $99-fee waived.
Successfully reviewed applications (a process initially estimated to take 5 days) become part of the marketplace catalogue which can be browsed and purchased directly on all Windows Phone 7 devices.
You can also have applications run in trial mode (detected with a simple API) and provide an in-application way for the user to navigation directly to the marketplace to purchase the full license to your application.
The marketplace currently sells Windows Mobile 6.x applications and should started accepting submissions for Windows Phone 7 application in October 2010.
With the launch of WP7 devices starting in late October and early November around the globe, the gold rush is now in full swing.
If you have experience with .NET development, Silverlight or web services, now’s the time to be re-introduce yourself to those skills on a new and exciting platform!
- The Windows Phone 7 developer portal
- The Consumer website
- The MSDN Library documentation on Windows Phone 7
- The MSDN Channel9 Windows Phone 7 Developer Training Kit
- The Author’s website
About the Author
He developed the first professional Windows Phone 7 boot camp tour in North America, training dozens of developers across Canada at Microsoft offices in the summer of 2010 featuring actual WP7 developer devices.
Colin is also the Principal Architect for DreamDigital with 17 years of hands-on experience, a professional trainer and speaker, as well as a user group leader in Ottawa. He has expertise in the areas of rich UI with WPF/Silverlight, cloud development with Azure and BI with SQL Server, along with in-depth knowledge of core technologies such as .NET, OData, WCF, WF, LINQ and WIF. He has developed award-winning simulation technology with rich UI, cloud-based learning portals and workflow-driven BI systems. He also created the first streaming video community site with Windows Media.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)