Fundamental Concepts in Windows Phone Development
- Understanding the Role of XAP Files
- The Windows Phone Capabilities Model
- The Threading Model for XAML-Based Graphics and Animation in Windows Phone
- Understanding the Frame Rate Counter
- The Windows Phone Application Analysis Tool
- Reading Device Information
- Applying the Model-View-ViewModel Pattern to a Windows Phone App
- Property Change Notification
- Using Commands
- Argument Validation
- A Platform-Agnostic Dialog Service
- Consuming Local Web Applications
Read Windows Phone 8 Unleashed and more than 24,000 other books and videos on Safari Books Online. Start a free trial today.
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.
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.
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).
FIGURE 2.1. The Application Deployment tool.
If you have not encountered XAP files before, they will certainly become relevant when you want to publish your first app to the Windows Phone Marketplace.