Appendix A - Tools, Frameworks, and Processes

This appendix describes the development and testing environment, tools, and techniques for building Windows® Phone 7 applications. It covers the following topics:

  • Setting up a development environment for Windows Phone 7
  • Using a hardware device during development
  • Developing Windows Phone 7 applications
  • Debugging Windows Phone 7 applications
  • Unit testing Windows Phone 7 applications
  • Additional tools and frameworks

Setting Up a Development Environment for Windows Phone 7

You can use Microsoft® Visual Studio® development system and the Windows Phone Developer Tools to simplify application development for Windows Phone 7. The Windows Phone Developer Tools include the following:

  • Visual Studio 2010 Express for Windows Phone
  • Integration Components and Templates for Visual Studio 2010
  • Windows Phone Emulator
  • Microsoft Silverlight® 4 Tools for Visual Studio
  • Microsoft Expression Blend® design software for Windows Phone
  • XNA® Game Studio 4.0

The tools install Silverlight, and you may see an error message during installation if you have a patched version of Silverlight already installed. You can uninstall Silverlight before you install the tools to avoid this, or you can just ignore this message.

If you are installing the tools on the Windows Vista® operating system with Service Pack 2, you must ensure that the following Windows updates that are a part of Knowledge Base article 971644, "Description of the Platform Update for Windows Server 2008 and the Platform Update for Windows Vista," have been applied. The following are the updates:

  • Update for Windows Vista (Knowledge Base article 971512)
  • Update for Windows Vista (Knowledge Base article 971513)
  • Update for Windows Vista (Knowledge Base article 971514)
  • Update for Windows Vista (Knowledge Base article 960362)
When running the emulator on Windows Vista, you may experience some audio glitches due to lost audio packets when playing audio, such as a media file or alarm.

You can obtain the Windows Phone Developer Tools from the App Hub website (

You will also need to install the Windows Phone Developer Tools October 2010 Update from the Microsoft Download Center (

Figure 1 illustrates Visual Studio 2010 Solution Explorer with the Windows Phone Developer Tools installed.


Figure 1

Visual Studio 2010 with the Windows Phone Developer Tools and emulator

If you have a touch-sensitive screen on your development computer, you can use this to operate the emulator. You can also install additional input devices, such as a tablet or an extra mouse, to test functions such as zoom that require "two finger" operations when you do not have access to a development computer that supports touch.

The emulator runs as a virtual machine, so you cannot use the Windows Phone Developer Tools within a virtual machine. When you run an application, it is packaged as a single XAP file and deployed to the emulator, which runs it automatically.
In addition, some of the capabilities of a Windows Phone 7 device are either not supported or are not fully functional in the emulator. For more information, see "Launcher and Chooser Support in Windows Phone Emulator" on MSDN® (

Expression Blend for Windows Phone

The Windows Phone Developer Tools also include Expression Blend 4 for Windows Phone. This provides an environment more suited to graphical design of the interface and makes implementation of features such as animations, gradient fills, and other attractive effects much easier than in it is in Visual Studio. You can open a project in Expression Blend or Visual Studio and then develop different parts of the project in the most suitable tool.

Figure 2 illustrates a Windows Phone solution open in Expression Blend. You can run it from here. It uses the same emulator as Visual Studio to display the application at run time.


Figure 2

Expression Blend 4 for Windows Phone

To see a video presentation that shows the power of Expression Blend for creating a complex interactive user interface (UI), see Authoring for Windows Phone, Silverlight 4 and WPF 4 with Expression Blend on the Mix 10 website (

To ensure that projects you create in Visual Studio can be opened in Expression Blend, check that the project file (.csproj) contains a configuration element in the default project properties section that correctly identifies it. You can do this by editing the project file in a text editor. For example, if the project is named MyTestProject, you should ensure that the correct <Configuration> element is included in the project file, as shown here:
<Project ToolsVersion="4.0" DefaultTargets="Build" ... >
<Configuration Condition=" '$(Configuration)' == '' ">MyTestProject</Configuration>

Additional Silverlight Controls for Windows Phone 7

You can obtain several additional and useful controls to use in your Windows Phone 7 applications by installing the Silverlight for Windows Phone Toolkit. The toolkit includes the following:

  • The GestureListener control that allows you to detect and handle the full range of gesture events, including Tap, DoubleTap, Hold, Drag, Flick, and Pinch
  • The DatePicker and TimePicker controls that make it easier for users to enter dates and times; these controls automatically localize to the correct date and time format setting
  • The ContextMenu control that makes it easy to incorporate shortcut menus in your application
  • The WrapPanel control that allows you to more easily manage the way content is displayed
  • The ToggleSwitch control that implements an on/off input metaphor
  • Additional UI themes for Windows Phone 7 applications

To obtain the Silverlight for Windows Phone Toolkit, see the Silverlight Toolkit page on CodePlex (

Using a Hardware Device during Development

You can develop and debug applications using a physical Windows Phone 7 device; in fact, this is recommended at least as a final step because the emulator does not provide all the functionality of a hardware device and may not portray your application exactly as it will appear and behave on a real phone.

Connecting a Physical Device

To connect a physical Windows Phone 7 device to your development computer, you must install the Microsoft Zune® software. If it was not provided with your device, you can download the Zune client software from the Zune website ( The Zune client allows you to connect your device using a USB cable or through a wireless connection.

Registering and Unlocking the Device

Before you can deploy, test, and debug Windows Phone applications on a physical device (a process known as side loading), you must create a developer account at the Microsoft Windows Phone Marketplace that grants you the right to publish and distribute your applications to the phone. If you have not already created an account on App Hub (, do so now.

After your account is verified, you must run the registration tool to unlock your phone. This uses the Zune software, which must be installed on your development computer, and the Windows Phone Developer Registration tool that is installed with the Windows Phone Developer Tools. After the registration succeeds, you can deploy applications to the phone. You can also unregister the device if required using the same tool.

You can install a maximum of 10 applications through side loading on a device. This does not include applications that have been installed through Windows Marketplace.

If you try to register and unlock a device that was previously registered, you must either rename the device using the Zune software, or go to the Windows Phone 7 portal and unregister the device.

For full details of the registration and unlocking process, see "How to: Use the Developer Registration Tool for Windows Phone" on MSDN (

Deploying Applications to the Device

After you connect and register your device, you can deploy an application to it during development by selecting Windows Phone 7 Device in the drop-down list in the Standard toolbar in Visual Studio or Visual Studio Express.

Applications are deployed as a single package with the .xap file extension that contains all the files required to run the application. Visual Studio creates the XAP package and deploys it to the emulator or physical device when you run the application in the development environment.

After you finish developing and testing your application, you can host it in your Windows Marketplace account ready for download to any Windows Phone 7 device. In the future, you will also be able to distribute internal applications for your organization through a private cloud-based service, although the mechanics of this are not currently determined.

A XAP package is actually a .zip file, and you can examine the contents of the package by renaming the file with the .zip file name extension and opening it in Windows Explorer. You will see the XML manifest file, the startup Extensible Application Markup Language (XAML) file, the assembly for your application and any other assemblies you added to the project, and the resources (such as images) that the application uses.

Using the Windows Phone Connect Tool

If you are building media applications that interact with the media APIs, you will not be able to debug these while the Zune software is running. For example, if your application uses Media Launchers or Choosers, the XNA Framework for song playback, or the Silverlight MediaElement control to play video or audio content, you must use the Windows Phone Connect Tool to debug your application.

The Windows Phone Connect Tool is part of the October 2010 update to the Windows Phone Tools, which is available from the Microsoft Download Center (

The Windows Phone Connect Tool (WPConnect.exe) is installed by default in the %ProgramFiles%\Microsoft SDKs\Windows Phone\v7.0\Tools\WPConnect folder. To use the tool:

  1. Connect your Windows Phone to your computer and ensure that it is detected by the Zune software.
  2. Close the Zune software after your Windows Phone is connected.
  3. Open a command prompt and navigate to the folder containing WPConnect.exe.
  4. At the command prompt, enter the command WPConnect.exe.

For more information, see "How to: Use the Windows Phone Connect Tool" on MSDN (

Developing Windows Phone 7 Applications

The Windows Phone Developer Tools install a series of templates into Visual Studio 2010, Visual Studio 2010 Express, and Expression Blend that provide a starting point for developing Windows Phone applications.

To use a Windows Phone 7 template in Visual Studio and Visual Studio Express

  1. On the Visual Studio File menu, point to New, and then click Project.
  2. In the Installed Templates tree view, expand Visual C#, and then click Silverlight for Windows Phone.
  3. In the central pane of the New Project dialog box, select the type of application you want to start with. If you want to display a list of items on the start page, select Windows Phone List Application. If you want to begin with a simple empty start page, select Windows Phone Application. If you are adding a new class library project to an existing Windows Phone 7 application, select Windows Phone Class Library. If you want to build an application that contains a Panorama or a Pivot control for displaying information, select Windows Phone Panorama Application or Windows Phone Pivot Application.
  4. Enter a name and specify the location for the new project, and then click OK.

To use a Windows Phone 7 template in Expression Blend for Windows Phone

  1. Do one of the following
    • In the startup dialog box, click New Project.
    • On the File menu, click NewProject.
  2. If you want to begin with a simple start page, select Windows Phone Application in the list of installed templates. If you want to display a list of data-bound items on the start page, select Windows Phone Databound Application. If you want to create a new control project, select Windows Phone Control Library. If you want to build an application that contains a Panorama or a Pivot control for displaying information, select Windows Phone Panorama Application or Windows Phone Pivot Application.
  3. Enter a name and specify the location for the new project, and then click OK.

The templates create a complete application with a "start" page that contains a list of sample data items and a "details" page that is displayed when you click an item in the list. You can see this application running in the emulator in Figure 1.

The template applications follow a basic Model-View-ViewModel (MVVM) pattern. The two UI pages are views of the data, although they do contain some code-behind to implement transitions and navigation, and to set the data context of the views. There are two view models, one for each view, that contain the public properties bound to the controls in the views and logic to create the list of items displayed in the views.

You can run the application as it stands to see how it works and to experiment with the emulator. The emulator can be rotated and resized as required. It also contains an implementation of Internet Explorer that you can use to browse the Internet or your own web-based applications.

For information about writing applications for Windows Phone 7, see the following resources:

For information about packaging and submitting your application to Windows Marketplace, see Chapter 7, "Interacting with Windows Marketplace."

Developing Trial Applications for Windows Phone 7

Windows Phone 7 allows you to easily publish trial versions of your application that users can install from Windows Marketplace. This is a useful way to demonstrate your application and allow users to decide if it is suitable for their requirements before they buy the full version. The trial version must reasonably represent the functionality and quality of the full application in order to obtain certification.

In general, you should avoid setting a time limit in trial versions so that users can install the trial more than once and will not find that it is blocked if they decide to evaluate it more fully at a later date. Instead, limit the use of some features so that the user can experience the main functionality and will want to buy the application to unlock these additional features.

Gg490779.note(en-us,PandP.10).gif Christine says:
Gg490779.personna-Christine-h50(en-us,PandP.10).pngTrial versions are a great way to tempt users to try and subsequently purchase your applications.

Windows Phone 7 implements the IsTrial method of the LicenseInformation class (located in the Microsoft.Phone.Marketplace namespace). Your application can call this method to discover whether the user is running a trial version or the full purchased version, and either display appropriate messages or direct the user to the page where they can purchase the full version. You can display the Windows Marketplace page for the current application by calling the Show method of the MarketplaceDetail class without specifying a content identifier. For more information about the MarketplaceDetail class, see Appendix C, "Leveraging Device Capabilities."

When you use the IsTrial method, be aware that this call involves communication with the Windows Marketplace servers. To minimize execution delays and communication cost for the user, call the method once when your application starts and cache the returned value for use throughout execution of the application.

Testing Trial Versions in an Emulator or Device

When you test an application using the emulator or an unlocked physical device, the IsTrial method will always return false. Instead, you can emulate trial mode using the Guide class (located in the Microsoft.Xna.Framework.GamerServices namespace). When you set the SimulateTrialMode property to true, the IsTrial method will return true. You should query the IsTrial method as soon as possible and cache the result because the value may change if the application later detects a valid license.

For more information about implementing trial versions of your applications, see "Creating Trial Applications for Windows Phone" on MSDN (

Developing Web Applications for Windows Phone 7

An alternative approach to building applications for Windows Phone 7 is to rely on the built-in Web browser within the operating system of the phone to display web pages, instead of designing and building a phone-based UI and using client-side code. This does not provide the same user experience, but it may be a useful approach when you already have a suitable application that you want to expose to phone users. You can also use a combination of the Web browser and a custom phone application. For example, you may consume services such as the Windows Live® log-on page to allow users to log on to a service and then use this logon in your phone-based application.

For a website to be usable on the small screen of a Windows Phone, you will most likely need to provide a more compact view of the pages than would be delivered to a normal desktop browser. You can use features in ASP.NET to detect the type of browser making the request and adapt the output simply by applying a different style sheet (for example, to remove extraneous content such as navigation bars and related content panels). Alternatively, you may decide to generate completely different pages with a simplified navigation model when you detect that the client is a small-screen device such as a phone.

These topics are not covered in this guidance, but you can learn more from the video presentation, Designing and Developing for the Rich Mobile Web on the Mix 10 website ( or by downloading the white paper, Designing Web Sites for Phone Browsers, from the Microsoft Download Center (

Debugging Windows Phone 7 Applications

If you are working in Visual Studio or Visual Studio Express, you can use the standard debugging tools to break, step through, and profile a Windows Phone 7 application. You can also view variable values and the execution tree and processes.

A Windows Phone 7 application uses Silverlight and Windows Presentation Foundation (WPF) to define the interfaces, so any debugging techniques you use in Silverlight and WPF also apply to Windows Phone 7. For example, there are some specific issues related to WPF styling and data binding that can arise in an application. These include the following:

  • Errors in the auto-generated partial class for a XAML component that prevent the component from being available to code in the page or the application. In most cases, you can resolve this by right-clicking the XAML file in Solution Explorer and then clicking Run Custom Tool to regenerate the partial class.
  • Errors in the XAML style definitions for components. These may occur in the App.xaml file or in other files within your application. Typically, the exception message indicates only that a COM component error has occurred and provides an HRESULT value. The simplest approach to resolving these types of errors are to minimize the surface area by temporarily removing some or all of the XAML styling definitions until the error disappears, and then reading them one by one to locate the faulty definition.
  • Data binding errors, such as using the wrong property name in a binding statement. This does not generate a run-time error, but the control property (such as the text) is not set. You can see a list of data binding errors in the Output window of Visual Studio or Visual Studio Express as the application executes. For example, you will see the following message if you specify binding to a property named City that does not exist in the data context.
    System.Windows.Data Error: BindingExpression path error: 'City' property not found on [your data context component name]. BindingExpression: Path='City' DataItem='[your data context item]'; target element is 'System.Windows.Controls.TextBlock' (Name='ItemText'); target property is 'Text' (type 'System.String').
  • Remote service access errors. If your application cannot retrieve data from a remote service, try copying the URL of the service from your code into a web browser to see if it is accessible. You can also download and install a web debugging proxy utility such as Fiddler or a similar utility to view all the HTTP(S) traffic between your application and the service. Fiddler is available from the Fiddler website (

One specific point to note when debugging Windows Phone 7 applications using the emulator is that certain actions within the phone may halt the debugger. For example, if the code opens a task or the launcher, or if it is tombstoned, execution may not continue automatically after the interruption. To continue debugging, press F5 in Visual Studio within 10 seconds of the task completing or the applications being reactivated.

Tools that intercept and analyze network traffic, such as Fiddler, are not supported in the current release of the phone tools. For example, if you configure Fiddler to track all network traffic, the emulator will not be able to connect to the network.

Unit Testing Windows Phone 7 Applications

Unit testing is the process of exercising individual business objects, state, and validation for your applications. A comprehensive set of unit tests written before you develop the code, and executed regularly during the entire development cycle, help to ensure that individual components and services are performing correctly and providing valid results.

You can use a special version of the Silverlight Unit Testing Framework adapted for use with Silverlight 3 to run unit tests for Windows Phone 7 applications. You can obtain this from Jeff Wilcox's site ( Jeff is a Senior Software Development Engineer at Microsoft on the Silverlight for Windows Phone team.

The Silverlight Unit Testing Framework adds the Silverlight Unit Test Application templates to the New Project dialog box in Visual Studio and Visual Studio Express, and you can use this to add a test project to your application. The framework allows you to execute tests that carry the standard Visual Studio test attributes and include the standard test assertions such as IsTrue and IsNotNull. It can be used to run all the unit tests in a solution or selected tests; it reports the results on the phone, showing full details of each test that passed or failed.

You can also run tests on the desktop using a traditional test framework such as the Microsoft Test Framework (MSTest), instead of deploying the application to the phone or the emulator and running it there under the test framework. This is generally faster, but you must be aware that there are some differences in the execution environment, and tests may behave differently on the desktop when compared to running on the emulator or a physical device. When performing integration testing, you should run the tests on the emulator or a physical device.

There are some tests that you cannot run in an emulator. For example, you cannot test the Global Positioning System (GPS) or the accelerometer. In these cases, you may prefer to use alternative testing techniques, such as creating mock objects that represent the actual service or component that your application uses and substituting these for the physical service or component.

To view a video presentation about unit testing using the Silverlight Unit Testing Framework, see Unit Testing Silverlight and Windows Phone Applications on the Mix 10 website (

Automated Unit Testing

It is possible to automate testing on the Windows Phone 7 emulator if you need to implement a continuous integration process and build Windows Phone 7 projects on a separate build server that does not have the Windows Phone Developer Tools installed. This requires setting up a folder for the external dependencies and editing the project files. For more information, see the post, "Windows Phone 7 Continuous Integration," on Justin Angel's blog (

It is also possible to automate building and deploying an application to a phone or emulator without using Visual Studio. This approach uses the Smart Device Connectivity API implemented in the assembly Microsoft.SmartDevice.Connectivity.dll. For more information about using this API, see "Smart Device Connectivity API Reference" on MSDN ( and "Windows Phone 7 Emulator Automation" on Justin Angel's blog (

Additional Tools and Frameworks

Not all the tools and frameworks you use in Silverlight applications on the desktop are suitable for developing Windows Phone 7 applications. For example, dependency injection containers such as the Unity Application Block (Unity) that demand certain security permissions or dynamically generate Microsoft intermediate language (MSIL) code cannot be deployed to the phone.

However, there are several tools and frameworks available that can be used successfully in Windows Phone 7 applications. The following are some examples:

If you want to access services exposed through Windows Communication Foundation (WCF) Data Services in Open Data Protocol (OData) format, you may consider using the special version of the OData client library for Windows Phone 7, which is implemented in the assembly System.Data.Services.Client.dll. To download it, see "OData Client Library for Windows Phone 7 Series" in the Microsoft Download Center (

You must use the WCF Data Service Client Utility (DataSvcUtil.exe) to create a suitable proxy class to access your services when using the OData client library. This utility is provided with the .NET Framework 4.0; it is typically installed in the folder Windows\Microsoft.NET\Framework[64]\v4.0. For more information, see "WCF Data Service Client Utility" on MSDN (

For more information about accessing remote data services in Windows Phone 7 Silverlight applications, see Chapter 2, "Designing Applications for Windows Phone 7."

These and all links in this book are accessible from the book's online bibliography. The URL to the bibliography can be found in the preface, in the final section, entitled, "Where to Go for More Information."