This chapter is from the book

Enabling and identifying app capabilities using the Marketplace Test Kit

The threading model for XAML graphics and animation

Optimizing animation performance

Enabling and reading the Frame Rate Counter

Using memory and execution profiling to identify bottlenecks

Retrieving device information using the DeviceStatus class

Applying MVVM to a Windows Phone app

Simplifying property change notification

Using commanding with MVVM

Validating method arguments

Building a platform agnostic dialog service

Enabling communication with local WCF services

This chapter begins with a look at the principal output of a Windows Phone Application project: the XAP file. The chapter discusses its composition and shows how to deploy a XAP file to a developer unlocked device.

The chapter then looks at the security capability model of the phone and at how this model is used to notify the user of any potential dangers before downloading an app from the Windows Phone Marketplace. You also look at using the Marketplace Test Kit to determine the capability requirements of your app.

Next, the chapter examines the threading model of XAML for Windows Phone and examines various performance considerations when creating animations or hiding and showing visual elements. You see how the Windows Phone frame rate counter works and learn how to interpret each reading shown on the display.

The chapter then looks at the Windows Phone Application Analysis tool. You see how to profile your app’s performance and memory usage, improve the responsiveness of your app, and help ensure that your app passes the Windows Phone Marketplace certification requirements.

The chapter turns to the custom code and commonly used techniques that you see throughout the book and that underpin many of the examples in subsequent chapters.

It is not uncommon to have many pages in a Windows Phone app, and having a solid codebase that contains a common infrastructure and frequently used services can save a lot of time. In fact, with more than 100 example pages included in the downloadable sample code, creating the code for this book would have taken considerably longer without it.

The techniques demonstrated are tried and tested approaches that help you build more maintainable apps and, by the end of the book, will have become exceedingly familiar to you if they are not so already.

The overview of the custom infrastructure begins with an exposé of the Model-View-ViewModel pattern, and you see how it is applied in the downloadable sample code. You then examine how property change notification is implemented and see techniques for improving the traditional implementation of INotifyPropertyChanged so that it works effortlessly with multithreaded apps.

Next, the chapter looks at the commanding infrastructure used throughout the book and examines a custom ICommand that allows you to specify handlers for command evaluation and execution. There is also a brief overview of the argument validation system commonly used in the sample code to validate method arguments.

The chapter then explores a custom dialog service that enables you to ask the user a question from your viewmodel, while remaining compatible with unit testing.

Finally, the chapter shows how to consume Windows Communication Foundation (WCF) services that reside on the same machine as the emulator, and outlines important steps to enable several of the apps in the downloadable sample code.

Understanding the Role of XAP Files

The output of a Visual Studio project normally consists of a multitude of files, which may include assemblies, images, config files, manifest files, and so forth. XAP (pronounced zap) files contain project output that is bundled up, ready for deployment.

XAP files have been around since the early days of Silverlight 2 (beta 1) and allow developers to easily deploy an entire Silverlight application to a remote server. On the Windows Phone platform, they are used to deploy an app to the Windows Phone Marketplace or to a developer unlocked device.

A XAP file is a compressed zip file that contains your project assemblies and resources, along with two application manifest files: AppManifest.xml and WMAppManifest.xml, both of which are located in the Properties directory of the project.

NOTE

It is a certification requirement that the XAP file contains both an AppManifest.xml file and a WMAppManifest.xml file. Both of these files are automatically generated when creating a new Windows Phone application from within Visual Studio. In nearly all cases, AppManifest.xml does not require changes by you. WMAppManifest.xml, however, may require editing depending on the features supported by your app.

When publishing to the Windows Phone Marketplace, your app’s XAP file is submitted as part of the publishing process.

To obtain the XAP file for your app, perform a build using a Release build configuration. You can then find the XAP file located in your app’s Bin/Release directory.

NOTE

When submitting your application to the Windows Phone Marketplace, the XAP file that you submit must be built using a release configuration without debug information or it may fail the certification process.

NOTE

The maximum allowed size of the XAP package file for Windows Phone Marketplace certification is 225MB.

The Application Deployment Tool

XAP files allow you to circulate your app to developers that have a developer unlocked device. This is done using the Application Deployment tool that is installed along with the Windows Phone SDK. The tool allows you to navigate to select a XAP file and deploy it to a connected phone device (see Figure 2.1).