129 69
English Pages 570 [537] Year 2012
Beginning Windows Phone App Development
Henry Lee Eugene Chuvyrov
Beginning Windows Phone App Development Copyright © 2012 by Henry Lee and Eugene Chuvyrov This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. ISBN 978-1-4302-4134-8 ISBN 978-1-4302-4135-5 (eBook) Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. President and Publisher: Paul Manning Lead Editor: Gary Schwartz Technical Reviewer: Robert Garrett Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Louise Corrigan, Morgan Ertel, Jonathan Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Markham, Matthew Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Gwenan Spearing, Matt Wade, Tom Welsh Coordinating Editor: Tracy Brown Copy Editors: Damon Larson, Tiffany Taylor Compositor: Bytheway Publishing Services Indexer: SPi Global Artist: SPi Global Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springeronline.com. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales. Any source code or other supplementary materials referenced by the author in this text is available to readers at www.apress.com. For detailed information about how to locate your book’s source code, go to www.apress .com/source-code/.
ii
7R(ULFDP\EHDXWLIXOZLIHIRUKHUORYHDQGVXSSRUW7KDQN\RXIRUDOZD\VEHLQJWKHUHIRUPH
ಧ+HQU\/HH
7R0DULDQQDಧP\IULHQGP\ZLIHP\PXVHಧDQGWRP\SDUHQWVIRUWKHLUJLIWRIXQFRQGLWLRQDO ORYH
ಧ(XJHQH&KXY\URY
iii
Contents at a Glance About the Authors.............................................................................................. xviii About the Technical Reviewer ............................................................................. xix Acknowledgments ................................................................................................ xx Introduction ......................................................................................................... xxi Chapter 1: Introducing Windows Phone and the Windows Phone Platform ...........1 Chapter 2: Building Windows Phone Applications................................................15 Chapter 3: Building Windows Phone 7 Applications Using Cloud Services As Data Stores ......................................................................................................37 Chapter 4: Catching and Debugging Errors ........................................................103 Chapter 5: Packaging, Publishing, and Managing Applications .........................129 Chapter 6: Working with the Accelerometer.......................................................151 Chapter 7: Application Bar..................................................................................171 Chapter 8: The WebBrowser Control...................................................................193 Chapter 9: Working with Controls and Themes ...................................................213 Chapter 10: Integrating Applications with the Windows Phone OS ....................235 Chapter 11: Creating Trial Applications..............................................................265 Chapter 12: Internationalization .........................................................................287 Chapter 13: Isolated Storage ..............................................................................311 Chapter 14: Using Location Services ..................................................................329 Chapter 15: Media...............................................................................................357
iv
Chapter 16: Working with the Camera and Photos.............................................379 Chapter 17: Push Notifications ...........................................................................405 Chapter 18: Reactive Extensions for .NET...........................................................445 Chapter 19: Security ...........................................................................................479 Index ...................................................................................................................513
v
Contents About the Authors.............................................................................................. xviii About the Technical Reviewer ............................................................................. xix Acknowledgments ................................................................................................ xx Introduction ......................................................................................................... xxi Chapter 1: Introducing Windows Phone and the Windows Phone Platform ...........1 Windows Phone Overview .................................................................................................4 Windows Phone Hardware Specifications .........................................................................4 Windows Phone Application Platform................................................................................6 Silverlight for Windows Phone.................................................................................................................. 6 XNA for Windows Phone ........................................................................................................................... 7 Tools ......................................................................................................................................................... 7 Cloud Services........................................................................................................................................ 11 Metro Design .......................................................................................................................................... 11
Application Development Life Cycle ................................................................................12 Summary .........................................................................................................................13 Chapter 2: Building Windows Phone Applications................................................15 Preparing Your Development Machine ............................................................................15 Building Your First Windows Phone Application ..............................................................15 Creating a Windows Phone Project ........................................................................................................ 16 Using the Windows Phone Silverlight Controls....................................................................................... 18 Writing the Windows Phone Code .......................................................................................................... 22 vi
#/.4%.43
Running the Silverlight Windows Phone Application.............................................................................. 23 Customizing the Windows Phone Application ........................................................................................ 25 Styling Your Application ......................................................................................................................... 28
Summary .........................................................................................................................34 Chapter 3: Building Windows Phone 7 Applications Using Cloud Services As Data Stores ..........................................................................................................37 Introducing the MVVM Pattern.........................................................................................38 Introducing Microsoft Azure and SQL Azure ....................................................................39 Creating a Cloud Database ..............................................................................................39 The Entity Framework ............................................................................................................................ 40 Creating an SQL Azure Database............................................................................................................ 40 Creating a Database in SQL Azure.......................................................................................................... 51
Creating a Cloud Service to Access the Cloud Database.................................................55 Creating a Windows Azure Project ......................................................................................................... 56 Generating an Object Model to Access the Cloud Database................................................................... 57 Implementing a WCF Service to Access the SQL Azure Database.......................................................... 63
Building a Phone Client to Access a Cloud Service .........................................................70 Creating a Windows Phone Project ........................................................................................................ 70 Building the UI ........................................................................................................................................ 71 Coding MainPage.................................................................................................................................... 77 Coding BoolToVisibilityConvert ............................................................................................................... 79 Adding a Reference to NotepadService.................................................................................................. 81 Coding NotepadViewModel..................................................................................................................... 82 Testing the Application Against NotepadService Deployed Locally........................................................ 89 Deploying the Service to Windows Azure............................................................................................... 90 Testing the Notepad Application Against the NotepadService Azure Service ........................................ 99
Summary .......................................................................................................................100
vii
#/.4%.43
Chapter 4: Catching and Debugging Errors ........................................................103 Debugging Application Exceptions ................................................................................103 Debugging Page Load Exceptions ........................................................................................................ 104 Debugging a Web Service Exception.................................................................................................... 109 Testing the Application......................................................................................................................... 115
Registering a Windows Phone Device for Debugging....................................................115 Handling Device Exceptions ..........................................................................................121 Creating the CatchDeviceExceptionDemo Project ................................................................................ 122 Building the User Interface ................................................................................................................... 123 Coding the Application.......................................................................................................................... 125 Testing the Finished Application .......................................................................................................... 127
Summary .......................................................................................................................127 Chapter 5: Packaging, Publishing, and Managing Applications .........................129 Windows Phone Application Publishing Life Cycle ........................................................129 Windows Phone Application Certification Requirements...............................................131 Application Policies .............................................................................................................................. 131 Content Policies.................................................................................................................................... 133 Application Submission Validation Requirements ................................................................................ 133 Application Certification Requirements ................................................................................................ 135
Submitting Your First Windows Phone Application to the Windows Phone Marketplace136 Packaging the Application .................................................................................................................... 136 Submitting the Application ................................................................................................................... 138 Updating Your Application .................................................................................................................... 146 Finding Your Application in the Marketplace........................................................................................ 148
Summary .......................................................................................................................149 Chapter 6: Working with the Accelerometer.......................................................151 Understanding Orientation and Movement ....................................................................151 viii
#/.4%.43
Calculating Distance............................................................................................................................. 154 Calculating Pitch, Roll, and Yaw........................................................................................................... 154
Introducing SDK Support for Accelerometers................................................................155 Retrieving Accelerometer Data......................................................................................156 Creating the CaptureAccelerometerData Project.................................................................................. 157 Building the UI ...................................................................................................................................... 158 Coding the Application.......................................................................................................................... 160 Testing the Finished Application .......................................................................................................... 163
Using Accelerometer Data to Move a Ball .....................................................................163 Creating the MoveBall Project .............................................................................................................. 164 Building the UI ...................................................................................................................................... 165 Coding the Application.......................................................................................................................... 167 Testing the Finished Application .......................................................................................................... 169
Summary .......................................................................................................................169 Chapter 7: Application Bar..................................................................................171 Introducing the Application Bar .....................................................................................173 Adding an Application Bar to a Windows Phone Application .........................................175 Adding Images for Use with Application Bar Buttons ........................................................................... 175 Adding a Global Application Bar Using XAML ....................................................................................... 177 Adding a Local Application Bar Using XAML......................................................................................... 178 Adding Menu Items............................................................................................................................... 179 Adding an Application Bar Using Managed Code ................................................................................. 181
Wiring Up Events to an Application Bar .........................................................................183 Adding Glue Code and a Worker Function to the Add Button ............................................................... 183 Reacting to Add Button Events ............................................................................................................. 184 Reacting to Save Button Events ........................................................................................................... 188 Reacting to Menu Events...................................................................................................................... 188 Adding Event Handlers with XAML ....................................................................................................... 189 ix
#/.4%.43
Using the ApplicationBar Class to Glue XAML and Managed Code....................................................... 190
Summary .......................................................................................................................191 Chapter 8: The WebBrowser Control...................................................................193 Introducing the WebBrowser Control.............................................................................193 Adding a WebBrowser Control.......................................................................................194 Using a WebBrowser Control to Display Web Content...................................................195 Using a WebBrowser Control to Display Local HTML Content .......................................198 Using a WebBrowser Control to Display Dynamic Content ............................................200 Saving Web Pages Locally .............................................................................................201 Choosing Display and Security Settings ........................................................................204 Viewport.........................................................................................................................204 CSS ....................................................................................................................................................... 204 Security ................................................................................................................................................ 205
A Brief Introduction to HTML5 Features.........................................................................206 HTML5 Features ................................................................................................................................... 206 Testing HTML5 Features on Windows Phone ....................................................................................... 208
Summary .......................................................................................................................212 Chapter 9: Working with Controls and Themes ...................................................213 Introducing the Metro Design System ...........................................................................213 Windows Phone Chrome....................................................................................................................... 214 Screen Orientations .............................................................................................................................. 216
Themes on Windows Phone Devices .............................................................................216 Applying a Theme................................................................................................................................. 217 Changing the Theme............................................................................................................................. 219 Detecting the Currently Selected Theme.............................................................................................. 221
x
#/.4%.43
Panorama and Pivot Controls ........................................................................................222 Using the Panorama Control................................................................................................................. 223 Using the Pivot Control ......................................................................................................................... 226
Understanding Frame and Page Navigation ..................................................................228 Creating a UI for the NavigationTest Project......................................................................................... 229 Adding Navigation Code ....................................................................................................................... 230 Adding Code to Pass Parameters Between Pages................................................................................ 230
Adding Transition Effects...............................................................................................231 Creating a UI ......................................................................................................................................... 231 Downloading TiltEffect.cs and Applying Dependency Properties ......................................................... 233
Summary .......................................................................................................................234 Chapter 10: Integrating Applications with the Windows Phone OS ....................235 Introducing Windows Phone Launchers and Choosers..................................................235 Launchers............................................................................................................................................. 236 Choosers............................................................................................................................................... 237
Working with Launchers and Choosers .........................................................................238 Creating the User Interface................................................................................................................... 238 Coding Application Logic ...................................................................................................................... 238
Working with the Windows Phone Application Life Cycle..............................................241 Observing Application Life Cycle Events .............................................................................................. 242 Managing Application State.................................................................................................................. 246 Best Practices for Managing the Application Life Cycle on the Windows Phone OS ............................ 252
Integrating with Facebook .............................................................................................252 A Few Words about OAuth.................................................................................................................... 253
Integrating into Windows Phone Hubs...........................................................................259 Integrating Your Application with the Music and Video Hub ................................................................ 260 Integration with SharePoint.................................................................................................................. 263
xi
#/.4%.43
Summary .......................................................................................................................263 Chapter 11: Creating Trial Applications..............................................................265 Understanding Trial and Full Modes ..............................................................................265 Using the IsTrial Method....................................................................................................................... 267 Using the Marketplace APIs.................................................................................................................. 269
Building a Trial Application............................................................................................271 Building the UI ...................................................................................................................................... 272 Connecting to a Web Service................................................................................................................ 277 Adding Page-to-Page Navigation.......................................................................................................... 279 Verifying Trial and Full Modes .............................................................................................................. 281 Adding the Finishing Touches .............................................................................................................. 282
Summary .......................................................................................................................284 Chapter 12: Internationalization .........................................................................287 Understanding Internationalization................................................................................287 Using Culture Settings with ToString to Display Dates, Times, and Text.......................289 Using the .NET Culture Hierarchy to Ensure Culture Neutrality .....................................292 Storing and Retrieving Current Culture Settings............................................................293 Using Resource Files to Localize Content......................................................................298 Localizing the Application Title and Tile ........................................................................305 Creating an Application Resource File.................................................................................................. 305 Using Resource DLL from the Windows Phone Project ........................................................................ 308 Creating Culture-Specific Resource DLLs............................................................................................. 309
Summary .......................................................................................................................310 Chapter 13: Isolated Storage ..............................................................................311 Working with Isolated Directory Storage .......................................................................312 Creating the IsolatedStorageStoreImageDemo Project ........................................................................ 313 Coding the UI ........................................................................................................................................ 314 xii
#/.4%.43
Coding the Application.......................................................................................................................... 316
Working with Isolated Storage Settings ........................................................................320 Creating a New Project......................................................................................................................... 321 Building the Application UI (XAML) ....................................................................................................... 322 Coding Application Behavior (C#) ......................................................................................................... 324
Summary .......................................................................................................................327 Chapter 14: Using Location Services ..................................................................329 Understanding Windows Phone Location ......................................................................329 Services Architecture ....................................................................................................329 Introducing the Windows Phone Location Service ........................................................330 and Mapping APIs..........................................................................................................330 Simulating the Location Service ....................................................................................330 Creating the GeoCoordinateWatcherDemo Project............................................................................... 331 Coding the UI ........................................................................................................................................ 332 Coding the Application.......................................................................................................................... 334 Testing the Finished Application .......................................................................................................... 336
Using GeoCoordinateWatcher and the Bing Maps Control to Track Your Movements...337 Registering with the Bing Maps Service Portal and Installing the Bing Maps SDK .............................. 338 Creating the BingMapDemo Project ..................................................................................................... 339 Coding the UI ........................................................................................................................................ 340 Coding the Application.......................................................................................................................... 343 Testing the Finished Application .......................................................................................................... 347
Plotting an Address on a Bing Maps Map and Working with the Bing Maps Service ....347 Creating the AddressPlottingDemo Application.................................................................................... 348 Adding a Service Reference to the Bing Maps GeoCodeService .......................................................... 348 Coding the UI ........................................................................................................................................ 350 Coding the Application.......................................................................................................................... 352
xiii
#/.4%.43
Testing the Finished Application .......................................................................................................... 354
Summary .......................................................................................................................354 Chapter 15: Media...............................................................................................357 Introducing MediaElement.............................................................................................357 Working with Video........................................................................................................358 Creating the MediaPlayerDemo Project................................................................................................ 359 Building the UI ...................................................................................................................................... 360 Coding the Application.......................................................................................................................... 363
Adding Sounds to an Application...................................................................................370 Creating the RobotSoundDemo Project ................................................................................................ 371 Building the UI ...................................................................................................................................... 372 Coding the Application.......................................................................................................................... 375
Summary .......................................................................................................................377 Chapter 16: Working with the Camera and Photos.............................................379 Introducing Windows Phone Photo Features.................................................................379 Using a Chooser to Take Photos........................................................................................................... 381 Using a Chooser to Open Photos .......................................................................................................... 385 Saving Photos to the Phone.................................................................................................................. 386
Integrating Your Application with Windows Phone........................................................388 Using the Apps Link to Launch an Application ..................................................................................... 389 Using Share to Upload PhotoCapture Snapshots to TwitPic ................................................................. 391
Manipulating Live Photo Feeds......................................................................................398 Summary .......................................................................................................................404 Chapter 17: Push Notifications ...........................................................................405 Understanding Push Notifications .................................................................................405 Toast Notifications................................................................................................................................ 405 Tile Notifications................................................................................................................................... 406 xiv
#/.4%.43
Raw Notifications ................................................................................................................................. 407
Introducing the Push Notifications Architecture ............................................................408 The Life Cycle of a Notification............................................................................................................. 409 The Push Notification Framework ........................................................................................................ 410
Implementing Toast Notifications..................................................................................411 Creating a Client Application ................................................................................................................ 413 Creating an Application to Send Notifications ...................................................................................... 418
Implementing Tile Notifications.....................................................................................424 Creating a Client Application ................................................................................................................ 425 Creating an Application to Send Notifications ...................................................................................... 425
Implementing Raw Notifications....................................................................................429 Creating a Client Application ................................................................................................................ 429 Creating an Application to Send Notifications ...................................................................................... 432 Testing Delivery of Raw Notifications................................................................................................... 433
Implementing a Cloud Service to Track Push Notifications...........................................434 Creating a WCF Service to Track Notification Recipients ..................................................................... 434 Modifying the Client to Call the WCF Service ....................................................................................... 439 Verifying Automated Push Notification Subscriber Tracking................................................................ 441
Using Push Notifications in the Real World....................................................................442 Setting Up Secure Web Services for Push Notifications................................................443 Summary .......................................................................................................................443 Chapter 18: Reactive Extensions for .NET...........................................................445 Introducing Reactive Programming ...............................................................................446 Rx.NET Subscription Pipeline.........................................................................................447 Implementing the Observer Pattern with Rx.NET ..........................................................448 Creating a Windows Phone Project ...................................................................................................... 448 Adding Code to Create and Read Observable Collections .................................................................... 449 xv
#/.4%.43
Using Rx.NET Event Handling to Search for Flickr Photographs....................................452 Creating a Windows Phone Project ...................................................................................................... 452 Adding a User Interface ........................................................................................................................ 453 Adding Logic to Search Flickr for Images............................................................................................. 454 Enhancing a Flickr Search with Throttling............................................................................................ 455 Adding an Animation that Plays as Flickr Images Load........................................................................ 458
Rx.NET Design Guidelines..............................................................................................462 Consider Drawing a Marble Diagram.................................................................................................... 463 Consider Passing a Specific Scheduler to Concurrency-Introducing Operators................................... 463
Using Rx.NET with Web Services to Retrieve Weather Data Asynchronously................464 Creating a Windows Phone Project ...................................................................................................... 465 Creating a User Interface...................................................................................................................... 466 Adding Logic to Get Weather Information............................................................................................. 468
Handling Errors in Rx.NET..............................................................................................471 Handling Data-Connection Issues with Rx.NET .............................................................472 Revising WeatherRx to Manage Slow Data Connections ...............................................473 Handling Multiple Concurrent Requests with Rx.NET ....................................................475 Summary .......................................................................................................................478 Chapter 19: Security ...........................................................................................479 Understanding Application Security ..............................................................................479 The Windows Phone Marketplace ........................................................................................................ 479 Submitting an Application to the Windows Phone Marketplace........................................................... 481 Sandboxed Execution and the Execution Manager .............................................................................. 483 Private Application Distribution Options ............................................................................................... 484
Implementing Network Security ....................................................................................484 Securing Connections with SSL............................................................................................................ 484 Testing and Opening an SSL Connection.............................................................................................. 485
xvi
#/.4%.43
Creating a Self-Signed Certificate ........................................................................................................ 486 Exporting a Self-Signed Certificate ...................................................................................................... 492 Installing a Self-Signed Certificate on Windows Phone ....................................................................... 494
Implementing Data Security ..........................................................................................495 Using HMACSHA1 and HMACHSHA256................................................................................................. 496 Using Rfc2898DeriveBytes and AES to Encrypt Data ........................................................................... 500 Information Rights Management .......................................................................................................... 504
Understanding Device Physical Security .......................................................................504 Meeting Certification Requirements ..............................................................................505 Applications Must Implement MSIL Code ............................................................................................. 505 Applications Must Not Implement Any Security-Critical Code.............................................................. 506 Capability List ....................................................................................................................................... 507
Obfuscating Your Application Code ...............................................................................508 Summary .......................................................................................................................512 Index ...................................................................................................................513
xvii
About the Authors Henry Lee is the founder of ToeTapz (www.toetapz.com) and New Age Solution (http://newagesolution.net), and is passionate about technology. He works with various Fortune 500 companies delivering mobile applications and rich Internet applications (RIAs). He is focusing his energy on delivering mobile applications on Windows Phone 7, Android, and iPhone. In his spare time, he helps his communities by delivering sessions at technology events. He enjoys discussing current trends in technology with other technologists and sharing business insights with fellow colleagues. You will often find Henry at a local cigar bar, enjoying a cigar and a drink while trying to come up with the next big mobile application.
Eugene Chuvyrov is an independent .NET consultant in beautiful Jacksonville, Florida. He was lucky enough to start working with Microsoft technologies when he graduated from college in 1998 and has been consistently delivering a positive return on investment to the clients that engage him. His most recent venture is an online event marketing startup, Packed House Events (http://packedhouseevents.com), which extends event creation, marketing, and electronic payments to anybody with Internet access. Eugene also facilitates the meetings of the Jacksonville Software Architecture Group, where he enjoys networking and learning from smart people. As soon as Eugene heard the news that a new mobile platform (Windows Phone 7) was being released by Microsoft, he was intrigued. It was hard to resist the temptation of wide-open possibilities to create smartphone applications using his favorite IDE and all the latest cloud- and functional programming–based technologies. This passion, discussed over a cigar with Henry at a local cigar bar, resulted in the book you now hold in your hands. He sincerely hopes you find it useful!
xviii
About the Technical Reviewer Rob Garrett has worked with SharePoint since the early beta version of Microsoft Office SharePoint Server 2007 and has leveraged his talents for SharePoint architecture and design with Portal Solutions— a SharePoint consultant company in Rockville, Maryland. Rob has extensive background in .NET technologies and has developed software for Microsoft frameworks since the early days of C++ and MFC. In pursuit of his career dreams, Rob left his birthplace in England for a journey to the United States on Thanksgiving Day, 1999, and enjoyed his first American meal from a gas station.
xix
Acknowledgments We would like to express our love and gratitude to our wives for encouraging us to finish this book. We are also grateful to Apress for giving us the opportunity to write this book on Windows Phone development. The staff at Apress made this book possible by spending many days and nights reviewing and editing the book to meet the tight deadline. Jon Hassell provided us with this unique opportunity to share our knowledge. Thank you, Jon, for believing in us. Also, we would like to show our appreciation to the coordinating editor, Tracy Brown, and our extremely diligent reviewers, Gary Schwartz and Rob Garrett. When the first and second edition were published, we also realized that there were many Apress staff members in the marketing department promoting the book; we would like to thank Lisa Lau and the marketing department, and Simon Yu for helping us get in contact with user groups for speaking engagements. We would also like to thank those who sent us e-mail with comments and those who blogged about our books on the Web with kind remarks. Many community members helped us improve upon our first and second editions by offering valuable feedback. We used that feedback to make this edition better and included a lot of information about new features of the latest release of the Windows Phone OS.
xx
Introduction This is the third edition of this book. We wanted to improve upon the first two editions and update the book with new features of the Windows Phone OS, as well as provide hands-on knowledge on how to program the plethora of features offered by Windows Phone devices. While the second edition was being written, Microsoft and Nokia formally announced their partnership and signed an agreement to seal their commitment. While we were writing the third edition, Nokia phones were being released to the European markets, and they should be coming to the United States in days. We hope that this book will provide developers with the practical knowledge that we gained by developing real-world applications; we also hope it will inspire developers to create many cool applications for the Windows Phone platform.
Who This Book Is For This book assumes that you have basic C# and .NET knowledge. This book will provide you with basic fundamentals and skills that you need to be successful in developing Windows Phone applications. You don’t need previous experience developing mobile applications—the only thing you need is a desire to learn new technology.
What You Need to Use This Book In order to write Windows Phone applications and test out the examples in this book, you’ll need to download the tools listed here. All of these are available at no charge from Microsoft. You’ll find additional information on how to install and use these tools in Part 1 of this book. •
Windows Phone Developer Tools RTW: http://download.microsoft.com/download/ 1/7/7/177D6AF8-17FA-40E7-AB53-00B7CED31729/vm_web.exe
•
Zune software: www.zune.net/en-us/products/software/download/
•
User Experience Design Guidelines for Windows Phone: http://go.microsoft.com/fwlink/?LinkID=183218
•
Windows Phone 7 Marketplace Certification Requirements: http://go.microsoft.com/?linkid=9730558
•
Microsoft SQL Server 2008 R2 Express: www.microsoft.com/express/Database/
•
Azure Tools for Visual Studio 1.2 June 2010: http://download.microsoft.com/ DOWNLOAD/1/F/9/1F96D60F-EBE9-44CB-BD58-88C2EC14929E/VSCLOUDSERVICE.EXE
xxi
).42/$5#4)/.
•
Azure SDK (June 2010): http://www.microsoft.com/windowsazure/sdk/
•
Windows Azure Platform Training Kit: http://www.microsoft.com/downloads/en/ details.aspx?familyid=413e88f8-5966-4a83-b309-53b7b77edf78
How This Book Is Organized This book contains 19 chapters, broken into 2 major parts. In Part 1, we will walk you through the development life cycle of the application. You will go from coding the simplest possible Hello World– style Windows Phone 7 application to building a full-blown, modern n-tier application that uses both the Windows Phone development platform and the unique cloud services that support it. The section concludes with step-by-step instructions on how to gain certification from Microsoft and offer an application to the public through the Windows Phone Marketplace. In Part 2, you will learn how to use specific features of Windows Phone devices in your applications, including the accelerometer, location services, the Application Bar, reactive extensions, application hub integration, application life cycle events, Isolated Storage, Silverlight, XAML, skinning controls, web browser controls, media elements, photos, push notifications, internalization, and security. While each of its chapters is a tutorial, you can also use Part 2 as a reference. Each chapter focuses on a single phone feature and provides step-by-step instructions on how to incorporate it into your application.
Where to Find Sources for the Examples The source code of all of the examples is available at www.apress.com/ or http://wp7apress.codeplex.com.
Send Us Your Comments We value your input. We’d like to know what you like about the book and what you don’t like about it. When providing feedback, please make sure you include the title of the book in your note to us. We’ve tried to make this book as error-free as possible. However, mistakes happen. If you find any type of error in this book, whether it is a typo or an erroneous command, please let us know about it. Visit the book’s web page at www.apress.com/9781430235965 and click the Errata tab. Your information will be validated and posted on the errata page to be used in subsequent editions of the book.
Contacting the Authors You can contact us directly at the following e-mail addresses: Henry Lee: [email protected] Eugene Chuvyrov: [email protected]
xxii
CHAPTER 1
Introducing Windows Phone and the Windows Phone Platform 4HISISANEXCITINGTIMEFORMOBILEAPPDEVELOPERSASTHESMARTPHONERACEHEATSUPBETWEENTHEMAJOR PLAYERS-ICROSOFT7INDOWS0HONE !PPLEI0HONE AND'OOGLE!NDROID!SADEVELOPER YOUAREFACED WITHANAMAZINGOPPORTUNITYTODEVELOPAMOBILEAPPLICATIONTHATCANBESOLDTOMILLIONSOFCONSUMERS WORLDWIDEUSINGANYOFTHESEPLATFORMS'ARTNERPREDICTSTHATBYTHESMARTPHONEMARKETWILL BOOM ANDTHEREWILLBEBILLIONSOFDOLLARSATSTAKE 2ECENTLY .OKIA ONEOFTHELARGESTMOBILEPHONEMAKERSINTHEWORLD ANNOUNCEDTHATITWILLREPLACE ITS3YMBIAN BASEDOPERATINGSYSTEMWITHTHE7INDOWS0HONE/34HEPARTNERSHIPBETWEEN-ICROSOFT AND.OKIAWILLPOTENTIALLYBOOST7INDOWS0HONESGLOBALMARKETSHARETOPERCENT MAKINGITEVEN MOREATTRACTIVEFOR7INDOWS0HONEDEVELOPERS 4HE7INDOWS0HONE-ARKETPLACE WHERECONSUMERSCANPURCHASEAPPLICATIONS OPENEDIN .OVEMBER9OUMIGHTCONSIDERDOWNLOADING:UNESOFTWAREFROMfffid]T]TcT] DB_a^SdRcbb^UcfPaTS^f][^PSS^f][^PSb^UcfPaTWc\TOVIEWTHECURRENT-ARKETPLACE ORYOUCAN NAVIGATEONYOURBROWSERTOffffX]S^fb_W^]TR^\T]DB\PaZTc_[PRT/NCEYOUHAVEDOWNLOADEDTHE :UNESOFTWAREANDFIREDITUP CLICKTHE-ARKETPLACE!003LINKS ANDYOUWILLBEABLETOSEEALLTHE 7INDOWS0HONEAPPLICATIONSCURRENTLYPUBLISHED ASSHOWNIN&IGURE 9OUWILLLEARNMOREABOUTTHE -ARKETPLACEIN#HAPTER
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
&IGURE 7INDOWS0HONE-ARKETPLACE 4HEREAREHUNDREDSOFIDEASFORAPPLICATIONSWAITINGTOBEDISCOVEREDANDDEVELOPEDBYPEOPLELIKE YOU4AKEALOOKAT3IMPLY3OLITAIRE 1UOTED3UCCESS $UCK#ALLER ANDTHEMOBILEBASEBALLGAMESHOWNIN &IGURE 7HICHOFTHESEWILLBEAMONGTHEFIRST7INDOWS0HONEHITSTOCATCHFIREWITHCONSUMERSAND SELLMILLIONSOFUNITS
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
&IGURE 7INDOWS0HONEAPPLICATIONS
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
7HATAPPLICATIONWILLYOUBEDEVELOPING7EVEWRITTENTHISBOOKTOGUIDEYOUTHROUGHTHESTEPSIT TAKESTOWRITEANDLAUNCHASUCCESSFULAPPLICATIONTOTHE7INDOWS0HONE-ARKETPLACE3OWHATAREYOU WAITINGFOR,ETSGETSTARTEDBYDIVINGINTOWHAT7INDOWS0HONEOFFERSTODEVELOPERSLIKEYOU
7INDOWS0HONE/VERVIEW -ICROSOFT7INDOWS0HONEISAGREATMOBILEPLATFORMBECAUSEITOFFERSALLOFTHEMODERNSMARTPHONE FEATURES INCLUDING'03 E MAIL 3-3 ACAMERA ANDAMUSICPLAYER ANDITALSOPROVIDESANEASY TO USE DEVELOPMENTFRAMEWORKTHATALLOWSMILLIONSOF.%4DEVELOPERSTOLEARNANDDEVELOPON7INDOWS 0HONEQUICKLY!LSO 7INDOWS0HONEOFFERSMULTITOUCHSCREENCAPABILITY ABEAUTIFULUSERINTERFACE5) THATIMPLEMENTSANEWMODERNDESIGNCALLED-ETRO SOCIALNETWORKINGSERVICESSUCHAS&ACEBOOK AND SUPPORTFORPOPULARE MAILSERVICESSUCHAS9AHOO (OTMAIL 'MAIL AND!/,AND IFYOUREACORPORATE USER -ICROSOFT%XCHANGE -OREOVER THEPLATFORMSHIPSWITHAVERSIONOF-ICROSOFT/FFICEAUNIQUE FEATUREOF7INDOWS0HONE9OUCANUSETHISVERSIONOF/FFICETOREAD EDIT SAVE ANDSYNC7ORD %XCEL ANDOTHER/FFICEFILES4HISMAKES7INDOWS0HONEAGREATMOBILEPLATFORMFORTHOSEWHOUSE/FFICEAT HOMEORATWORK7INDOWS0HONECANALSOINTEGRATEWITH8BOX,)6% MAKINGITAGREATCHOICEFORGAMERS -ICROSOFT7INDOWS0HONEUSESTHE:UNESOFTWARETOSYNCINSTALLEDAPPLICATIONS PICTURES AND MUSIC ANDBACKUPANDFLASH/3UPDATES!SADEVELOPER YOULLALSOUSE:UNEINCONJUNCTIONWITH6ISUAL 3TUDIOTODEBUGYOURAPPLICATIONSONAREALDEVICEMOREONTHATIN#HAPTER -ICROSOFTALSOINTRODUCESTHECONCEPTOFAHUBWITHTHE7INDOWS0HONEA0EOPLEHUBWHEREUSERS CANSTOREALLOFTHEIRCONTACTSANDSOCIALNETWORKINGCONNECTIONSA-USICHUBWHERECONSUMERSCAN LISTENTO DOWNLOAD ANDPURCHASEMUSICANDAN!PPHUB ALSOKNOWNASTHE-ARKETPLACE WHEREYOU WILLPUBLISHTHEAPPLICATIONSYOUCREATE (AVINGASMARTPHONETHATSAHITWITHCONSUMERSISIMPORTANTBECAUSETHECONSUMERMARKETPLACEIS WHERETHEGREATESTOPPORTUNITIESLIE/NEOFTHEGREATTHINGSABOUT7INDOWS0HONEISTHAT-ICROSOFT IMPOSESTHEHARDWARESPECIFICATIONSONTHEPHONEMANUFACTURER MAKINGITEASYFORYOUTODEVELOPAN APPLICATIONWITHOUTWORRYINGABOUTWRITINGDEVICE SPECIFICCODE&ORANYFUTURERELEASEOF7INDOWS 0HONE YOUAREGUARANTEEDTHATTHEAPPLICATIONYOUWRITETODAYWILLWORKREGARDLESSOFTHEBRANDOFTHE MOBILEDEVICE ASLONGASITRUNS-ICROSOFT7INDOWS0HONE .ATURALLY YOUWANTTOKNOWWHATLANGUAGEYOULLNEEDTOMASTERFORYOURWORK&OR7INDOWS 0HONE THELANGUAGESOFCHOICETODAYARE#AND6ISUAL"ASICTHEPRIMARY.%4LANGUAGES!SFORAN APPLICATIONDEVELOPMENTFRAMEWORK YOUHAVETWOCHOICES3ILVERLIGHTOR8.!3ILVERLIGHTAND8.!BOTH USETHECORE.%4&RAMEWORK9OUWILLLEARNMOREABOUTTHETWOFRAMEWORKSLATERINTHISCHAPTER BUT FIRSTLETSTAKEACLOSERLOOKATTHEHARDWAREFEATURESYOUCANEXPECTONA7INDOWS0HONEDEVICE
7INDOWS0HONE(ARDWARE3PECIFICATIONS +NOWINGWHATSINCLUDEDINTHE-ICROSOFT7INDOWS0HONEHARDWARESPECIFICATIONSWILLHELPYOU PREPAREFORTHESPECIALNEEDSOFTHEPROJECTSYOUWILLUNDERTAKE4ABLE LISTSTHEMINIMUMHARDWARE REQUIREMENTSTHATANY7INDOWS0HONEMANUFACTURERMUSTMEET ANDITALSOINCLUDESSUGGESTIONSASTO HOWTHEYCANIMPACTDEVELOPERSLIKEYOU
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
4ABLE 7INDOWS0HONE-INIMUM(ARDWARE2EQUIREMENTS
Hardware Feature
Description
-USTDISPLAYAT76'! ¯
9OUONLYNEEDTOWORRYABOUTONESCREENRESOLUTION4HISMAKESITEASYTO DEVELOPANAPPLICATION
&OUR POINT MULTITOUCH CAPABLE
4HISISUNIQUETO7INDOWS0HONE ANDYOUCANUSETHISFEATURETOCREATEFOUR PLAYERGAMES4HEREISDEFINITELYROOMFORINNOVATIONUSINGTHISPARTICULAR FEATURE
$IRECT8HARDWARE ACCELERATION
4HISMEANSTHEPHONEWILLHAVEAGRAPHICALPROCESSINGUNIT'05 ALLOWING GRAPHICALLYINTENSETASKSTOBEOFFLOADEDTOTHEGRAPHICSCHIPSOFTHEPARTICULAR MOBILEDEVICE4HISWILLHELPYOUCREATEVERYSMOOTHANDRESPONSIVE APPLICATIONSANDGAMES4HISALSOMEANSTHAT$GAMESAREPOSSIBLE
'03
7ITHTHISFEATURE YOULLBEABLETOCREATELOCATION AWAREAPPLICATIONS3EE #HAPTERTOLEARNABOUTLOCATIONSERVICES HOWTOUSE"ING-APS ANDHOW TOPLOT'03DATAONAMAP
!CCELEROMETER
4HISFEATUREWILLMEASURETHECHANGEINTHEACCELERATIONINTHEMOBILEDEVICE 4HEACCELEROMETERISPOPULARINGAMES BUTISALSOUSEFULINAPPLICATIONS SUCH ASSPIRIT LEVELAPPLICATIONS3EE#HAPTERTOLEARNMOREABOUTTHISFEATURE
#OMPASS
7ITHTHIS YOUCANFINDNORTH SOUTH EAST ANDWEST
,IGHT
4HISFEATURECANBEUSEDASAFLASHFORTHECAMERA
$IGITALCAMERA
4HISALLOWSYOUTOTAKEPICTURESANDSHARETHEMON&ACEBOOKANDOTHERSOCIAL NETWORKINGSITES,EARNMOREABOUTTHISFEATUREIN#HAPTER
(ARDWARECONTROLS "ACK 3TART AND3EARCH BUTTONS
%VERY7INDOWSPHONEWILLHAVETHREEBUTTONSONTHEFRONTOFTHEPHONE+EEP INMINDTHATYOUWILLBEREQUIREDTOUSETHE"ACKBUTTONFORGOINGBACKWARD INYOURAPPLICATION BECAUSEHAVINGASEPARATE"ACKBUTTONINTHEAPPLICATION MIGHTCONFUSETHEUSER9OUWILLLEARNMOREABOUTINTEGRATINGTHEHARDWARE BUTTONSINTOANAPPLICATIONIN#HAPTER
$ATACONNECTION SUPPORT#ELLULAR NETWORKAND7I &I
4HISFEATUREALLOWSYOUTOCONNECTTOTHE)NTERNET9OUCANCREATE7EB SERVICESANDSUBSCRIBETOTHEMFROMYOURAPPLICATIONS ORYOUCANSUBSCRIBE TOTHIRD PARTY!0)SSUCHAS4WITTEROR&ACEBOOKINYOURAPPLICATION
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
Hardware Feature
Description
-"OF2!-AND'" +EEPINMINDTHATYOURAPPLICATIONCANUSEONLY-"OFMEMORYUNLESSTHE OFFLASHSTORAGE DEVICEHASMORETHAN-"OFMEMORY)FYOURAPPLICATIONDOESNOTRESPECT THISREQUIREMENT ITWILLNOTPASSTHE-ARKETPLACECERTIFICATIONPROCESS3EE #HAPTERFORMOREDETAILS !LSO THE'"OFFLASHMEMORYUSEDFORSTORAGEISSHAREDAMONGOTHER APPLICATIONS SOIFYOUARESAVINGANYKINDOFSTATICDATAINTOTHE)SOLATED 3TORAGE YOUMUSTCHECKIFTHESPACEISAVAILABLEANDHANDLETHEEXCEPTION APPROPRIATELY&ORMOREDETAILSONTHIS SEE#HAPTER
!44WILLCARRY3AMSUNGS&OCUS ,'S1UANTUM AND(4#S3URROUND4 -OBILEHASANNOUNCED THATITWILLCARRY(4#S($ AND6ERIZONWILLCARRYTHE(4#4ROPHY!LSO 3PRINTWILLCARRYTHE(4# !RRIVE9OUWILLFINDTHATALLMAJORPROVIDERSWILLBECARRYINGONEORMORE7INDOWS0HONEDEVICES9OU CANFINDMOREINFORMATIONONTHERELEASEOFNEW7INDOWSPHONESAT fff\XRa^b^UcR^\fX]S^fb_W^]TT]dbQdh&_W^]TbPb_g )NTHENEXTSECTION YOUWILLLEARNHOWTHESOFTWAREBEHINDTHESEPOWERFULCONSUMERSMARTPHONES PROVIDESAGREATPLATFORMFORDEVELOPERS
7INDOWS0HONE!PPLICATION0LATFORM -ICROSOFTDIDNOTINVENTANYNEWLANGUAGESORFRAMEWORKSFORTHE7INDOWS0HONEAPPLICATIONPLATFORM 4HECOMPANYSIMPLYADAPTEDITSEXISTINGFRAMEWORKS4HISMEANSTHATYOUWILLBEABLETOPROGRAMUSING #AND6ISUAL"ASICWITHTHE.%4&RAMEWORK.%4PROVIDESACOMMONBASE CLASSLIBRARYWITHWHICH EVERY-ICROSOFT.%4PROGRAMMERWILLBEFAMILIARITINCLUDESSUPPORTFORMULTITHREADING 8-, ,).1 COLLECTIONS EVENTS DATA EXCEPTIONS INPUTOUTPUT)/ SERVICEMODEL NETWORKING TEXT LOCATION REFLECTION GLOBALIZATION RESOURCES RUNTIME SECURITY ANDDIAGNOSTICS AMONGMANYOTHERFEATURES /NTOPOFTHECORE.%4&RAMEWORK THE7INDOWS0HONEAPPLICATIONPLATFORMCONSISTSOFTWOMAJOR FRAMEWORKS3ILVERLIGHTAND8.!9OULLUSE3ILVERLIGHTPRIMARILYFORBUSINESSAPPLICATIONSANDSIMPLE$ GAMES3ILVERLIGHTUSESTHE%XTENSIBLE!PPLICATION-ARKUP,ANGUAGE8!-, ADECLARATIVEMARKUP LANGUAGEFORCREATINGCOMPELLING5)S$ESIGNERSWILLHAVETREMENDOUSFLEXIBILITYINCREATING5)SFOR 7INDOWS0HONEBYUSINGFAMILIARTOOLSLIKE!DOBE)LLUSTRATOR 0HOTOSHOP AND-ICROSOFT%XPRESSION $ESIGN THEYCANCREATEAVECTOR BASED5)THATCANBEEASILYEXPORTEDTO8!-,8.!ISPRIMARILYUSEDFOR CREATINGGAMES4HEFRAMEWORKCOMESWITHAGAMEENGINETHATALLOWSYOUTOCREATELOOP BASEDGAMES ANDA$ENGINETHATALLOWSYOUTOCREATE$GAMES )NTHEFOLLOWINGSECTIONS YOUWILLLEARNMOREDETAILSABOUTTHEMAINCOMPONENTSOFTHE7INDOWS 0HONEAPPLICATIONPLATFORM3ILVERLIGHT 8.! TOOLS ANDCLOUDSERVICES
3ILVERLIGHTFOR7INDOWS0HONE 3ILVERLIGHTHASHISTORICALLYBEENAWEB BASEDTECHNOLOGY ANDITOPERATESWITHINAWEBBROWSERPLUG IN 3ILVERLIGHTPROVIDESYOUWITHASANDBOXEDEXPERIENCETHATABIDESBYTHERULESOFTHEWEBBROWSERSIN OTHERWORDS WITHINA3ILVERLIGHTAPPLICATION YOUCANTACCESSTHENATIVE/3UNLESSYOUHAVETHE NECESSARY!0)S4HISARCHITECTUREMAKES3ILVERLIGHTVERYCOMPELLINGFORUSEIN7INDOWS0HONEFROMA SECURITYSTANDPOINT BECAUSE7INDOWS0HONEPROVIDESTHESAMERESTRICTIONOFPROVIDING!0)SONLYTO DEVELOPERSANDLIMITINGACCESSTOTHENATIVE/3 !NOTHERBENEFITISTHAT3ILVERLIGHTUSES8!-, WHICHCANBEUSEDTODECLAREVECTOR BASEDGRAPHICS ANDCREATEANIMATIONS!NYDESIGNERFAMILIARWITHVECTOR BASEDAPPLICATIONS SUCHAS!DOBE)LLUSTRATOR
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
AND-ICROSOFT%XPRESSION$ESIGN CANEASILYCREATEHIGHLYVISUALELEMENTSINVECTOR BASEDFORMATTHAT CANBEEXPORTEDTO8!-,4HISMEANSTHATDESIGNERSHAVEFULLCONTROLOVERTHELAYOUT LOOKANDFEEL AND GRAPHICALASSETS MAKING3ILVERLIGHTANEXTREMELYPOWERFULCHOICEFORCREATINGCONSUMER ORIENTED APPLICATIONS!LSO 8!-,PROVIDESAPOWERFULDATA BINDINGFEATURETOTHECONTROLS MAKINGITIDEALFOR CREATINGBUSINESS ORIENTEDAPPLICATIONS
8.!FOR7INDOWS0HONE ,IKE3ILVERLIGHT 8.!ISNOTANEWTECHNOLOGY8.!ISUSEDINCREATING8BOXGAMESVIAMANAGEDCODE)TIS ANATURALCHOICEFORCREATINGGAMESSINCE7INDOWS0HONEHAS8BOX,)6%INTEGRATION ALLOWING8.! BASED8BOXGAMESTOBEEASILYPORTEDOVERTO7INDOWS0HONE4HEONLYTHING8BOXGAMEDEVELOPERS HAVETOWORRYABOUTISTHESCREENRESOLUTION WHICHCANEASILYBEADJUSTEDANDFIXED 8.!PROVIDESARICHFRAMEWORKFORGAMEDEVELOPMENT INCLUDINGAGAMELOOPENGINE $AND$ ENGINES ANDTHEABILITYTOMANAGEGAMEASSETSLIKEMODELS MESHES SPRITES TEXTURES EFFECTS TERRAINS ANDANIMATIONS
4OOLS 9OUCANDOWNLOADTHETOOLSYOULLNEEDFORDEVELOPING7INDOWS0HONEAPPLICATIONSFROM Wcc_)RaTPcT\bS]R^\T]dbW^\TVTccX]VNbcPacTS4HE'ETTING3TARTEDPAGEALSOFEATURESRICH DOCUMENTATIONANDTUTORIALS9OUSHOULDALSOCONSIDERDOWNLOADINGTHE5)$ESIGNAND)NTERACTION 'UIDETOUNDERSTANDTHE-ETRODESIGNGUIDELINESTHAT-ICROSOFTRECOMMENDSASBESTPRACTICESWHEN DEVELOPINGAPPLICATIONS
6ISUAL3TUDIO )FYOUDONTHAVEAPURCHASEDVERSIONOF6ISUAL3TUDIOONYOURDEVELOPMENTMACHINE THENTHE DEVELOPMENTTOOLTHATYOUDOWNLOADFROM-ICROSOFTWILLINSTALLAFREEVERSIONOF6ISUAL3TUDIO %XPRESSFOR7INDOWS0HONE ASSHOWNIN&IGURE 6ISUAL3TUDIOISABSOLUTELYNECESSARYBECAUSEITCAN BEUSEDTODESIGN DEBUG CREATE ANDPACKAGEPROJECTS ANDAUTOMATICALLYGENERATEPACKAGEMANIFESTS)T ALSOINCLUDESAPHONEEMULATORUPONWHICHYOUMAYTESTYOURRESULTS)N#HAPTER YOUWILLLEARNTO DEBUGANDRUNTHEEMULATORFROM6ISUAL3TUDIO9OUWILLALSOUSE6ISUAL3TUDIOTOCREATEAPACKAGEFOR PUBLICATIONTOTHE!PPHUB
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
&IGURE -ICROSOFT6ISUAL3TUDIO%XPRESSFOR7INDOWS0HONE
%XPRESSION"LEND 9OUWILLNEED%XPRESSION"LENDSHOWNIN&IGURE IFYOUWANTTODEVELOPCOMPELLINGAPPLICATIONS USING3ILVERLIGHTFOR7INDOWS0HONE4YPICALLY%XPRESSION"LENDISUSEDBYDESIGNERS ANDMANYOFTHE %XPRESSION"LENDFUNCTIONALITIESARESIMILARTOTHOSEFOUNDIN!DOBE)LLUSTRATOR 0HOTOSHOP OR %XPRESSION$ESIGN.OTETHATYOUCANIMPORTANY)LLUSTRATOROR0HOTOSHOPFILESINTO%XPRESSION"LENDIF YOUAREUSING%XPRESSION$ESIGN YOUCANEXPORT%XPRESSION$ESIGNFILESDIRECTLYTOA8!-,FILE %XPRESSION"LENDALSOPROVIDESAWAYTOCREATEANIMATIONSEQUENCES!LTHOUGHYOUCANCREATE ANIMATIONIN6ISUAL3TUDIOUSING8!-, ITWOULDBEVERYDIFFICULTTOWRITECOMPLEX8!-,CODETO REPRESENTCOMPLEXGRAPHICSORANIMATIONSEQUENCES)TISBESTTOLEAVECOMPLEXGRAPHICSANDANIMATIONS TO%XPRESSION"LEND
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
&IGURE -ICROSOFT%XPRESSION"LENDFOR7INDOWS0HONE
7INDOWS0HONE%MULATOR 4HE7INDOWS0HONEEMULATOR SHOWNIN&IGURE ISINTEGRATEDWITH6ISUAL3TUDIO ANDITSIMULATESA REAL7INDOWS0HONEDEVICE(OWEVER THEREARETHINGSTHATYOUCANTDOINTHEEMULATOR&ORINSTANCE YOUCANTTESTANYFEATURESTHATREQUIREAPHYSICALDEVICE SUCHASTHEACCELEROMETER THE'03 THE COMPASS THE&-RADIO 3-3 E MAIL PHONECALLING THECONTACTLIST ORTHECAMERA (OWEVER YOUCANUSEWHATARECALLEDREACTIVEEXTENSIONSTOSIMULATETHEDATAFEEDFROMAREAL PHONE)N#HAPTER YOULLLEARNHOWTOUSEREACTIVEEXTENSIONSTOSIMULATETHEACCELEROMETERAND'03 READINGSSOTHATYOUCANWORKWITHTHEEMULATORWITHOUTHAVINGTHEACTUALDEVICEITSELF
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
&IGURE 7INDOWS0HONEEMULATOR
$OCUMENTATIONAND3UPPORT 4HEREAREMANYWAYSTOGETHELPIFYOUGETSTUCKONAPROBLEMWHILEDEVELOPINGYOURAPPLICATION4HE 7INDOWS0HONE4RAINING+IT ATWcc_)RaTPcT\bS]R^\T]dbW^\TVTccX]VNbcPacTS CONTAINSHOW TOSONSPECIFICTECHNOLOGY9OUCANGOTOWcc_)U^ad\bbX[eTa[XVWc]TcU^ad\b%"Pb_gTOASK QUESTIONSRELATEDTO3ILVERLIGHTFOR7INDOWS0HONE)FYOUHAVEOTHER7INDOWS0HONEnRELATEDQUESTIONS YOUCANVISITWcc_)b^RXP[\bS]\XRa^b^UcR^\5^ad\bT]DBfX]S^fb_W^]T&bTaXTb4HE7INDOWS 0HONEDEVELOPMENTTEAMPUTSOUTMANYUSEFULBLOGSTHATYOUCANFOLLOWAT Wcc_)fX]S^fbcTP\Q[^VR^\fX]S^fbN_W^]TQf_STe/FCOURSE THEREIS7INDOWS0HONE DOCUMENTATIONAT-3$.GOTOWcc_)\bS]\XRa^b^UcR^\T]db[XQaPahUU#!$"$EB(!Pb_g!LSO YOUCANUSETHISBOOKASAREFERENCE ANDFEELFREETOREACHOUTTOITSAUTHORSATTHISBLOG Wcc_)Q[^VC^TCP_iR^\
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
#LOUD3ERVICES 7ORKINGWITHA7INDOWS0HONEAPPLICATIONTHATREQUIRESSAVINGDATATOANONLINEDATABASEISTRICKY4HE FIRSTBIGPROBLEMISTHATYOUDONTKNOWINADVANCEHOWPOPULARYOURAPPLICATIONWILLWINDUPBEING)FIT BECOMESPOPULAR YOUMIGHTSUDDENLYFINDMILLIONSOFPEOPLEUSINGYOURAPPLICATIONANDSAVINGTHEDATA TOITSDATABASEATARATETHATWOULDREQUIREANENTERPRISE LEVELSOLUTION9OULLALSONEEDTOFINDA7EB SERVICETOPROVIDE!0)STOYOURAPPLICATIONTOALLOWFORTHESAVINGOFDATATOTHEDATABASEBECAUSE 7INDOWS0HONEAPPLICATIONSCANTDIRECTLYCONNECTTOTHEDATABASE 4HISISWHERETHE-ICROSOFT!ZURECLOUDCOMESIN-ICROSOFT!ZUREPROVIDES7INDOWS!ZURESERVICES FORDEPLOYINGSERVICES7#& 7INDOWSSERVICE ANDITALSOPROVIDES31,!ZURE WHICHALLOWSYOUTOSCALE UPTHEDATABASEINFINITELYASYOURDEMANDGROWS9OUWILLLEARNMOREABOUTTHE-ICROSOFT!ZURECLOUDIN #HAPTER -ICROSOFTALSOPROVIDES"ING-APSSERVICES WHICHYOUCANUSEFREELYIFYOUAREDEVELOPINGA 7INDOWS0HONEAPPLICATION!LONGWITH"ING-APSSERVICES -ICROSOFTPROVIDES"ING-APSCONTROLSIN 3ILVERLIGHT WHICHYOUCANUSEIN7INDOWS0HONE9OUWILLLEARNABOUT"ING-APSANDLOCATIONSERVICES IN#HAPTER 0USHNOTIFICATIONSERVICESAREHOSTEDINTHECLOUDASWELL4HESEALLOWYOUTOPUSHMESSAGESTOTHE PHONEAVERYPOWERFULMESSAGINGMECHANISM9OUWILLLEARNMOREABOUTTHISIN#HAPTER8BOX,)6% SERVICESALSORESIDEINTHECLOUD9OUCANTAKEADVANTAGEOFTHESESERVICESINYOURAPPLICATIONSASWELL HOWEVER THISTOPICISBEYONDTHESCOPEOFTHISBOOK 9OULEARNEDABITABOUT7INDOWS0HONEANDTHE7INDOWS0HONEPLATFORMINTHEPREVIOUSSECTIONS )NTHEFOLLOWINGSECTIONSANDINTHERESTOFTHISBOOK YOUWILLLEARNABOUT7INDOWS0HONEAPPLICATION DEVELOPMENT
-ETRO$ESIGN -ICROSOFTISTARGETING7INDOWS0HONETOWARDBUSYPROFESSIONALS)NORDERTOPROVIDEACOMPELLING5) -ICROSOFTCAMEUPWITHTHE-ETRODESIGN WHICHISDERIVEDFROMTRANSPORTATIONINDUSTRYTYPOGRAPHY ANDPUTSHEAVYEMPHASISONSIMPLEANDCLEANDESIGNELEMENTS4HE-ETRODESIGNFOLLOWSFIVEPRINCIPLES v
!NEMPHASISONCLEAN LIGHT OPEN ANDCLUTTER FREEDESIGNANDSIMPLE TO READ TYPOGRAPHY BECAUSECONSUMERSWILLUSETHEIR7INDOWS0HONEDEVICESFORE MAIL 3-3 &ACEBOOK AND4WITTERWHILEONTHEGO
v
!FOCUSONCONTENT WHERETHEDESIGNPREMISEISGEAREDTOWARDHOWTHECONTENTIS PRESENTED
v
!FOCUSONTHESEAMLESSINTEGRATIONOFHARDWAREANDSOFTWARE
v
!NEMPHASISONGESTURES WHERETHEDESIGNENABLESAWORLD CLASSMULTITOUCHUSER EXPERIENCE
v
!FOCUSONMAKINGAPPLICATIONSSOULFULANDALIVE WHERETHEINFORMATIONTHAT MATTERSMOSTTOTHEUSERISPRESENTEDINAWAYTHATISEASILYACCESSIBLEBYASINGLE TOUCH
9OUCANFINDOUTMOREABOUTTHE-ETRODESIGNBYDOWNLOADINGTHEDOCUMENTPROVIDEDBY-ICROSOFT ATWcc_)V^\XRa^b^UcR^\Uf[X]Z.;X]Z83, '"! '
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
!PPLICATION$EVELOPMENT,IFE#YCLE )TSIMPORTANTTOUNDERSTANDTHEAPPLICATIONDEVELOPMENTLIFECYCLEHELPSYOUPREPAREFORIT)N DEPTH DISCUSSIONOFTHEAPPLICATIONDEVELOPMENTLIFECYCLE INCLUDINGTHECERTIFICATIONPROCESS ISPROVIDEDIN #HAPTER&IGURE SHOWSAHIGH LEVELVIEWOFTHEDEVELOPMENTLIFECYCLEOFA7INDOWS0HONE APPLICATION
&IGURE !PPLICATIONDEVELOPMENTLIFECYCLE !SADEVELOPER YOUWILLSTARTOUTATTHE!PPHUBANDREGISTERYOUR7INDOWS,IVE)$)FYOUDONT HAVEA7INDOWS,IVE)$ YOULLBEPROVIDEDWITHTHEOPPORTUNITYTOCREATEONE /NCEYOUVESIGNEDUP ATTHE!PPHUB YOUREGISTERYOURPHYSICALDEVICESOTHATYOUCANDEBUGONTHEREALDEVICE+EEPINMIND THATYOUCANADDUPTOTHREEDEVICES5SING6ISUAL3TUDIOANDOR%XPRESSION"LEND YOUWILLBECREATING YOURAPPLICATIONANDDEBUGGINGUSINGTHEEMULATORORTHEDEVICEYOUREGISTERED/NCETHEAPPLICATIONIS CREATED YOUNEEDTOSUBMITTHEAPPLICATIONFORTHECERTIFICATIONPROCESS
#(!04%2 ).42/$5#).'7).$/730(/.%!.$4(%7).$/730(/.%0,!4&/2-
)NORDERTOENSURETHATYOURAPPLICATIONWILLPASSTHE-ARKETPLACECERTIFICATIONPROCESS ITSAGOOD IDEATOREADANDUNDERSTANDTHEAPPLICATIONCERTIFICATIONDOCUMENTFOUNDAT Wcc_)\bS]\XRa^b^UcR^\T]db[XQaPahWW '#'#"!'e,EB(!!(Pb_g!SPARTOFTHECERTIFICATION PROCESS YOURAPPLICATIONWILLGOTHROUGHASERIESOFVALIDATIONSTEPSTHATCHECKTHEAPPLICATIONAND CONTENTPOLICIES ANDTHEPACKAGING CODE PHONEFEATUREDISCLOSURE LANGUAGE ANDIMAGEREQUIREMENTS 9OURAPPLICATIONWILLALSOBETESTEDONRELIABILITY PERFORMANCE RESOURCEMANAGEMENT PHONE FUNCTIONALITY ANDSECURITY4HECERTIFICATIONPROCESSISINPLACETOHELPPROMOTEQUALITYAPPLICATIONSTO CONSUMERS PROTECTCONSUMERSFROMMALWARE ANDPROTECT-ICROSOFTSERVICES /NCETHEAPPLICATIONPASSESTHECERTIFICATIONPROCESS ITWILLBEDEPLOYEDTOTHE-ARKETPLACEAND THENDOWNLOADEDANDUSEDBYCONSUMERS4HECONSUMERSWHOUSEYOURAPPLICATIONWILLPROVIDERATINGS ANDCOMMENTS4HE!PPHUBISUSEDTOGENERATEREPORTSONHOWYOURAPPLICATIONISPERFORMINGINTHE -ARKETPLACE"ASEDONTHEFEEDBACKYOURECEIVE YOUCANCHOOSETODEPLOYANUPDATEDVERSIONWITHBUG FIXESANDNEWFEATURES9OURULTIMATEGOALISTOCREATEACOMPELLINGAPPLICATIONTHATYOUKNOW CONSUMERSWILLUSEANDTOPUBLISHTHISAPPLICATIONTOTHE-ARKETPLACE 4HEREISANANNUALSUBSCRIPTIONFEEOFFORDEPLOYINGAPPLICATIONSTOTHE-ARKETPLACE4HISFEE GIVESYOUACCESSTOTHE7INDOWS0HONE-ARKETPLACEANDTHE8BOX-ARKETPLACE)NTHE7INDOWS 0HONE-ARKETPLACE YOUCANSUBMITANUNLIMITEDNUMBEROFPAIDAPPLICATIONSANDFIVEFREE APPLICATIONSADDITIONALSUBMISSIONSCOST)NTHE8BOX-ARKETPLACE YOUCANSUBMITUPTOTEN GAMES 9OUCANOBSERVE-ARKETPLACEACTIVITIESSUCHASCOMMENTS RATINGS ANDNUMBEROFAPPSSOLD THROUGHTHEREPORTPROVIDEDSOTHATYOUCANEFFECTIVELYIMPROVEYOURSALESANDMARKETINGEFFORTS -ICROSOFTTAKESPERCENTOFTHECONSUMERAPPPRICEYOUKEEPPERCENT9OUCANCHOOSEDIRECT DEPOSITSOTHATTHEMONEYGOESDIRECTLYTOYOURBANKACCOUNTYOUWILLRECEIVEYOURPAYMENTSONTHEFIRST DAYOFEACHMONTHFROM-ICROSOFT
3UMMARY 9OUAREABOUTTOEMBARKONTHEJOURNEYTODEVELOPAPPLICATIONSFOR7INDOWS0HONE9OUHAVEACHANCE TODEVELOPANAPPLICATIONTHATCANBEUSEDBYMILLIONSANDBECOMEPARTOFABILLION DOLLARGLOBALAPP MARKET 4HISCHAPTERPROVIDEDAGENERALOVERVIEWOF7INDOWS0HONEFEATURES HARDWARESPECIFICATIONS THE DEVELOPMENTPLATFORM ANDTHE-ARKETPLACE)N#HAPTER YOUWILLBUILDYOURFIRST7INDOWS0HONE APPLICATION USING6ISUAL3TUDIO %XPRESSION"LEND ANDTHE7INDOWS0HONECONTROLS
CHAPTER 2
Building Windows Phone Applications 4HISCHAPTERWILLPREPAREYOUWITHEVERYTHINGYOUNEEDTOGETSTARTEDWITH7INDOWS0HONE DEVELOPMENT9OUWILLLEARNABOUTTHE7INDOWS0HONEEMULATOR 6ISUAL3TUDIO%XPRESS AND -ICROSOFT%XPRESSION"LEND9OUWILLUSETHESETOOLSTOCREATEYOURFIRST7INDOWS0HONEAPPLICATION "EFOREYOUCANWRITEYOURFIRSTAPPLICATION HOWEVER YOUNEEDTODOWNLOADANDINSTALLTHETOOLS)N THENEXTSECTION WELLSHOWYOUHOW
0REPARING9OUR$EVELOPMENT-ACHINE 7INDOWS0HONEDEVELOPERTOOLVERSIONWASUSEDINTHEWRITINGOFTHISBOOK4HELATEST7INDOWS 0HONEDEVELOPERTOOLSANDPATCHESCANBEDOWNLOADEDFROMWcc_)RaTPcT\bS]R^\T] dbW^\TVTccX]VNbcPacTS4HE7INDOWS0HONEDEVELOPERTOOLSe\NfTQTgT WILLINSTALLTHEFOLLOWING v
4HEFREEVERSIONOF6ISUAL3TUDIO%XPRESSFOR7INDOWS0HONETHE PROGRAMMERSDEVELOPMENT)$% )FYOUALREADYHAVEAPAIDVERSIONOF6ISUAL 3TUDIOINSTALLED THATWILLWORKASWELL
v
4HE7INDOWS0HONEEMULATOR4HISISUSEDTORUNANDTESTTHE7INDOWS0HONE APPLICATION
v
3ILVERLIGHTFOR7INDOWS0HONE4HISISTHE3ILVERLIGHTFRAMEWORKFOR7INDOWS 0HONE BASEDON3ILVERLIGHTTECHNOLOGY3EE#HAPTERFORADESCRIPTIONOFTHE SUBTLEDIFFERENCESBETWEEN3ILVERLIGHTANDTHE7INDOWS0HONE3ILVERLIGHT FRAMEWORK
v
-ICROSOFT%XPRESSION"LENDFOR7INDOWS0HONE4HISTOOLCANBEUSEDTODESIGN 5)S
v
8.!'AME3TUDIO4HISINCLUDESTOOLSFORDEVELOPINGGAMES4HISWASORIGINALLY DEVELOPEDFORPROGRAMMINGFOR8BOX BUTTHE8.!8BOXFRAMEWORKWAS SUBSEQUENTLYPORTEDTO7INDOWS0HONE
/NCEYOUHAVEINSTALLEDTHE7INDOWS0HONEDEVELOPERTOOLS YOUCANSTARTTOBUILDYOURFIRST 7INDOWS0HONEAPPLICATION
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.3
"UILDING9OUR&IRST7INDOWS0HONE!PPLICATION )NTHISSECTION YOULLBUILDASIMPLE(ELLO7ORLDAPPLICATIONUSINGTHE3ILVERLIGHTFRAMEWORK#REATING THEAPPLICATIONWILLPROVIDEYOUWITHANOPPORTUNITYTOUSE6ISUAL3TUDIO%XPRESSFOR7INDOWS 0HONE THE7INDOWS0HONEEMULATOR ANDSOME7INDOWS0HONE3ILVERLIGHTCONTROLS,ATERINTHIS CHAPTER YOUWILLUSE%XPRESSION"LENDTODESIGN3ILVERLIGHTCONTROLS4HEFINALAPPLICATIONISSHOWNAT THEENDOFTHISCHAPTER!CLICKOFITS/+BUTTONWILLDISPLAYTHEWORDSh(ELLO7ORLDvINATEXTBOX"EFORE YOUCANGETSTARTED HOWEVER YOUMUSTFIRSTCREATEA6ISUAL3TUDIO%XPRESSPROJECT
#REATINGA7INDOWS0HONE0ROJECT 4OGETSTARTED FIREUP6ISUAL3TUDIO%XPRESSANDCREATEAPROJECT
4OLAUNCH6ISUAL3TUDIO%XPRESS SELECT3TART➤!LL0ROGRAMS➤-ICROSOFT 6ISUAL3TUDIO%XPRESS➤-ICROSOFT6ISUAL3TUDIO%XPRESSFOR 7INDOWS0HONE
#REATEANEWPROJECTBYSELECTING&ILE➤.EW➤0ROJECTONTHE6ISUAL3TUDIO %XPRESSMENU ASSHOWNIN&IGURE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.3
&IGURE #REATINGANEWPROJECTIN6ISUAL3TUDIO%XPRESS
&ROMAMONGTHETHREE#TEMPLATESTHAT6ISUAL3TUDIO%XPRESSDISPLAYS ONITS.EW0ROJECTDIALOGPAGE SELECTTHE7INDOWS0HONE!PPLICATION6ISUAL #TEMPLATE ASSHOWNIN&IGURE
.OTE4HEREARETHREEDIFFERENT7INDOWS0HONE6ISUAL3TUDIO%XPRESSPROJECTTEMPLATES4HE7INDOWS 0HONE!PPLICATIONTEMPLATEISATEMPLATEFORONE PAGEAPPLICATIONS4HE7INDOWS0HONE,IST!PPLICATIONTEMPLATE USESA,IST"OXCONTROLANDPAGENAVIGATIONFRAMEWORKTOCREATEAPPLICATIONSWITHMULTIPLEPAGES4HE7INDOWS 0HONE#LASS,IBRARYTEMPLATECANBEUSEDTOCREATEACLASSLIBRARYTHATCANBEREFERENCEDBYOTHER7INDOWS0HONE PROJECTS
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.3
&ORTHEPURPOSESOFTHISEXERCISE CHANGETHENAMEOFTHENEWPROJECTTO 7T[[^F^a[SBYCHANGINGTHETEXTINTHE.AMEBOX ASSHOWNIN&IGURE 9OU CANALSOCHANGETHELOCATIONWHERETHEPROJECTWILLBESAVEDBYCHANGINGTHE PATHINTHE,OCATIONBOX
&IGURE #REATINGANEW3ILVERLIGHT7INDOWS0HONEAPPLICATION
&INALLY SELECT/+INTHE.EW0ROJECTDIALOG AND6ISUAL3TUDIO%XPRESS WILLCREATEYOURPROJECT THEELEMENTSOFWHICHAREDISPLAYEDIN&IGURE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.3
&IGURE (ELLO7ORLD3ILVERLIGHT7INDOWS0HONEPROJECT "YDEFAULT TWO4EXT"LOCKCONTROLSWILLBEPLACEDONTHESCREENYOUCANSEETHISINTHEDESIGNVIEWAT THEFARLEFTIN&IGURE 7ITHAPHONEPROJECTREADYTOROLL ITSTIMETOBRINGTHEAPPLICATIONTOLIFEBYADDINGSOME FUNCTIONALITYANDCREATINGA5),ETSSTARTWITHTHE5) ADDINGSOMECONTROLSTOITSBLANKDESIGNSURFACE ANDSOMEAREASWHEREITCANDISPLAYTEXT
5SINGTHE7INDOWS0HONE3ILVERLIGHT#ONTROLS 4HENEXTSTEPISTOADD3ILVERLIGHTCONTROLSTOTHE7T[[^F^a[S7INDOWS0HONEAPPLICATIONCREATEDINTHE PREVIOUSSTEPS9OULLBESETTINGTHEPROPERTIESOFTHECONTROLSSOTHATTHECONTROLSCANBESIZEDAND POSITIONEDAUTOMATICALLYINBOTHTHEPORTRAITANDLANDSCAPEMODESOF7INDOWS0HONE )NTHE7INDOWS0HONEDESIGNVIEWWINDOW CLICKTHE=4EXT"LOCK)NTHE0ROPERTIES WINDOWSINTHELOWER RIGHTCORNEROFTHE6ISUAL3TUDIO)$% CHANGETHECTgcPROPERTYFROM=TO7T[[^F^a[S.OTICETHATTHENEWTEXTNOWAPPEARSONTHEDESIGNSURFACE ASSHOWNIN &IGURE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.3
&IGURE 2ENAMINGTHEAPPLICATIONWINDOWTITLE .OWOPENTHE6ISUAL3TUDIO%XPRESSTOOLBOX WHEREYOULLFINDSOMECONTROLSFORTHE 7T[[^F^a[S5))FYOUCANTFINDTHETOOLBOX SELECT6IEW4OOLBOXFROMTHE6ISUAL3TUDIO%XPRESS MENU!LISTOFCONTROLSWILLBEDISPLAYEDONAVERTICALPANELONTHELEFTSIDEOFTHE6ISUAL3TUDIO)$% AS SHOWNIN&IGURE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.3
&IGURE 6ISUAL3TUDIO%XPRESSTOOLBOXCONTAINING7INDOWS0HONECONTROLS 4HE6ISUAL3TUDIOTOOLBOXCONTAINSTHE7INDOWS0HONECONTROLSTHATSHIPWITHTHE7INDOWS0HONE DEVELOPERTOOLS9OULLBEUSINGTHEMTHROUGHOUTTHISBOOKTODEVELOPINCREASINGLYSOPHISTICATED5)S 9OUCANADDANYOFTHESETOYOUR5)BYDRAGGINGTHEMTOTHE7INDOWS0HONEDESIGNSURFACEIN6ISUAL 3TUDIO 4OCREATETHEINTERFACEFORTHE7T[[^F^a[SAPPLICATION LETSFIRSTADDA4EXT"OXTODISPLAYSOMETEXT 4ODOSO DRAGA4EXT"OXCONTROLFROMTHETOOLBOXTOTHEDESIGNSURFACEDIRECTLYBELOWTHEPAGETITLE 4EXT"LOCK7HENTHE4EXT"OXCONTROLISSUCCESSFULLYPLACEDONTHEPHONESDESIGNSURFACE ITWILLBE AUTOMATICALLYSELECTED)NTHE0ROPERTIESWINDOWIFYOUCANTFINDTHE0ROPERTIES7INDOW GOTO6IEW➤ 0ROPERTIES7INDOW CHANGETHEFOLLOWING4EXT"OXPROPERTIES
3ET7IDTHAND(EIGHTTO0dc^
3ET(ORIZONTAL!LIGNMENTTOBcaTcRW
3ET6ERTICAL!LIGNMENTTOC^_
2ESIZETHE4EXT"OXWIDTHSOTHATTHEREISENOUGHROOMTOITSRIGHTFORAN/+ BUTTON
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.3
3ET=P\TTOTXT-ESSAGE
)FYOUFOLLOWTHESESTEPSPROPERLY YOUSHOULDSEETHEFOLLOWING8!-,INTHE8!-,EDITORAREA +CTgc1^g7TXVWc,0dc^:7TXVWc,&!7^aXi^]cP[0[XV]\T]c,AXVWcZETacXRP[0[XV]\T]c,C^_FXScW, %- 9OURLAYOUTSHOULDBEDONE)N8!-,VIEW LOOKFORTHEGRIDCONTAININGTHECONTROLSYOUJUSTADDED )TSHOULDLOOKSIMILARTOTHIS +6aXSg)=P\T,2^]cT]c6aXS6aXSA^f, - +CTgc1^g7TXVWc,0dc^ 2A40C4C01;4JSQ^LJDbTaL JDbTa8SLJd]X`dTXST]cXUXTaL=>C=D;; J=P\TLJ]ePaRWPaL$=>C=D;; 2>=BCA08=CJ?:NDbTaL?A8C=D;; JDbTa8SLJd]X`dTXST]cXUXTaL=>C=D;; J=^cTCTgcLJ]ePaRWPaL\Pg=>C=D;; J3TbRaX_cX^]LJ]ePaRWPaL$=>C=D;; 2>=BCA08=CJ?:N=^cTL?A8 0;C4AC01;4JSQ^LJ=^cTL F8C72742:0332>=BCA08=CJ5:N=^cTNDbTaL5>A486=:4HJDbTa8SL A454A4=24BJSQ^LJDbTaLJDbTa8SL 6> 0;C4AC01;4JSQ^LJ=^cTL2742:2>=BCA08=CJ5:N=^cTNDbTaL 6>
!FTEREXECUTINGTHESCRIPT NOTICETHATWHENYOUEXPANDTHETABLESFROM =^cT_PS31IN/BJECT%XPLORER YOUWILLSEETWOTABLES =^cTANDDbTa ASSHOWN IN&IGURE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
&IGURE .OTEPAD$"TABLES 9OUNOWHAVEALIVEDATABASEIN31,!ZURE)NTHENEXTSECTION YOUWILLCREATEA7EBSERVICEUSING 7INDOWS#OMMUNICATION&OUNDATION7#& 4HE7EBSERVICELAYERPROVIDESMANAGED!0)STHATTHE PHONEAPPLICATIONCANUSETOACCESSTHEDATABASE
#REATINGA#LOUD3ERVICETO!CCESSTHE#LOUD$ATABASE 9OUWILLcreateA7#&SERVICECALLED=^cT_PSBTaeXRTTHATWILLBECONSUMEDBYTHE7INDOWS0HONE =^cT_PSAPPLICATION4HINKOF=^cT_PSBTaeXRTASTHELAYERTHATPROVIDESMANAGED!0)STOTHE=^cT_PS APPLICATION=^cT_PSBTaeXRTWILLUTILIZETHE%NTITY&RAMEWORKTOGENERATEOBJECTMODELSBASEDONTHE DATABASETABLESSCHEMA ANDITWILLALSOGENERATEAPERSISTENCELAYERTHATPERFORMSTHEDATABASE OPERATIONS WHICHOTHERWISEYOUWOULDHAVETOCODEYOURSELF 4HEFOLLOWINGSTEPSWILLPROVIDEYOUWITHINSTRUCTIONSONCREATINGANDDEPLOYING=^cT_PSBTaeXRTTO 7INDOWS!ZURE9OUWILLCREATEA7#&!ZURESERVICEANDRUNITFROMYOURCOMPUTER ANDTHENYOUWILL PACKAGEANDDEPLOYTHEPROJECTTOTHE!ZURECLOUD WHEREYOUWILLBEABLETOCONFIGUREITTORUNMULTIPLE SERVICESIFYOURAPPLICATIONDEMANDINCREASES
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
#REATINGA7INDOWS!ZURE0ROJECT 9OUWILLCREATEA7INDOWS!ZURE=^cT_PSBTaeXRTPROJECTIN6ISUAL3TUDIOINTHEFOLLOWINGSTEPS)NORDER TOCREATE!ZURESERVICES YOUNEEDTODOWNLOADTHE!ZURETOOLSAND3$+FROM fff\XRa^b^UcR^\fX]S^fbPidaTfX]S^fbPidaTSTUPd[cPb_g
#REATEANEW7INDOWS0HONE!PPLICATIONBYSELECTING&ILEh.EW0ROJECTON THE6ISUAL3TUDIOCOMMANDMENU3ELECTTHE#LOUDINSTALLEDTEMPLATEONTHE LEFT ANDCHOOSE7INDOWS!ZURE#LOUD3ERVICEFROMTHELISTONTHELEFTSEE &IGURE .AMETHE!ZURESERVICE=^cT_PSBTaeXRTANDCLICK/+
&IGURE 7INDOWS!ZURE#LOUD3ERVICEPROJECT
9OUWILLBEPROMPTEDTOSELECTTHETYPEOFROLE.OTEHERETHATIFYOUWANTTO HOSTTHEWEBPROJECT YOUNEEDTOSELECT!30.%47EB2OLE&ORTHE=^cT_PS 7#&SERVICE SELECT7#&3ERVICE7EB2OLE ASSHOWNIN&IGURE ANDCLICK THEARROWPOINTINGTOTHERIGHT)NTHE#LOUD3ERVICE3OLUTIONDIALOG YOUWILL SEEF25BTaeXRTFTQA^[TIFYOUHOVERYOURMOUSEOVERTHEITEM ALITTLEPENCIL ICONWILLAPPEAR#LICKTHEPENCILICON ANDCHANGETHENAMETO =^cT_PSBTaeXRTA^[TALSOSHOWNIN&IGURE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
&IGURE 3ELECTING7#&3ERVICE7EB2OLE
'ENERATINGAN/BJECT-ODELTO!CCESSTHE#LOUD$ATABASE .OWTHATYOUHAVETHEBASICPLUMBINGFORIMPLEMENTINGA7#&SERVICE ITSAGOODTIMETOIMPLEMENTA PERSISTENCELAYERTHATALLOWSYOUTOINTERACTWITHTHEDATABASE4HE%NTITY&RAMEWORKWILLACTASAN/2- TOOLTHATWILLTAKEDATABASETABLESANDCREATEEQUIVALENTOBJECTMODELS ANDHANDLEMANYOFTHETEDIOUS TASKSOFCODINGMETHODSSUCHASADD DELETE UPDATE ANDSEARCH !TTHEENDOFTHISSECTION YOUWILLHAVECREATEDTWOOBJECTMODELS DbTaAND=^cT WITHWHICHYOU CANWORKDIRECTLYINTHECODE4HE%NTITY&RAMEWORKPROVIDESTHEABILITYTOSAVETHESEMODELSDIRECTLY BACKTOTHEDATABASE )NTHEFOLLOWINGSTEPS YOUWILLADDAN%NTITY&RAMEWORKITEMTOTHEPROJECTANDTHENCONNECTTO =^cT_PS31IN31,!ZUREANDGENERATEOBJECTMODELS
2IGHT CLICKTHE=^cT_PSBTaeXRTA^[TPROJECTFOUNDIN3OLUTION%XPLORER AND CHOOSE!DDh.EW)TEM
#HOOSE$ATAFROMTHE)NSTALLED4EMPLATESLISTONTHELEFT CHOOSE!$/.%4 %NTITY$ATA-ODEL ANDNAMETHEMODEL=^cT_PSBTaeXRTTS\gSEE &IGURE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
&IGURE !DDINGAN%NTITY&RAMEWORKITEM
9OUWILLBEPROMPTEDWITHTHE%NTITY$ATA-ODEL7IZARD ASSHOWNIN&IGURE #LICK.EXT
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
&IGURE 4HE%NTITY$ATA-ODEL7IZARD
#LICKTHE.EW#ONNECTIONBUTTON7HEN#HOOSE$ATA3OURCEAPPEARS SELECT -ICROSOFT31,3ERVERFROMTHELIST ASSHOWNIN&IGURE #LICK#ONTINUE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
&IGURE 4HE#HOOSE$ATA3OURCEWINDOW
9OUWILLBEPROMPTEDWITHA#ONNECTION0ROPERTIESWINDOW&ORTHESERVICE NAME ENTERTHE31,!ZURESERVERNAMETHATYOUACQUIREDFROMTHEPREVIOUS STEPS ANDENTER.OTEPAD!DMINAND?/bbf^aSASYOURUSERNAMEAND PASSWORD&ROMTHEh3ELECTORENTERADATABASENAMEvDROP DOWN SELECT =^cT_PS31 ASSHOWNIN&IGURE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
&IGURE 4HE#ONNECTION0ROPERTIESWINDOW
#LICK/+ ANDYOUWILLRETURNTOTHE%NTITY$ATA-ODEL7IZARDWINDOW3ELECT 9ES INCLUDETHESENSITIVEDATAINTHECONNECTIONSTRINGRADIOBUTTON ANDCLICK .EXT
)FYOUEXPANDTHETABLES YOUWILLSEETHETWOTABLES=^cTANDDbTa THATYOU CREATEDPREVIOUSLY3ELECTBOTHOFTHETABLES ASSHOWNIN&IGURE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
&IGURE #HOOSINGTHEDATABASEOBJECTS
!CCEPTTHEDEFAULTOPTIONFOREVERYTHINGELSE ANDCLICK&INISH9OUWILLRETURN TOTHE6ISUAL3TUDIOPROJECTANDSEE=^cT_PSTS\g WHICHCONTAINSTWOOBJECT MODELS DbTaAND=^cT ASSHOWNIN&IGURE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
&IGURE %NTITYMODEL.OTEPADEDMX 9OUNOWHAVEDbTaAND=^cTOBJECTMODELSTHATYOUCANWORKWITHIN=^cT_PSBTaeXRT)NTHENEXT SECTION YOUWILLPREPARE=^cT_PSBTaeXRT WHICHWILLIMPLEMENTSIMPLECREATE READ UPDATE ANDDELETE OPERATIONSUSINGTHEENTITYMODELTHATYOUGENERATEDINTHISSECTION
)MPLEMENTINGA7#&3ERVICETO!CCESSTHE31,!ZURE$ATABASE .OWTHATYOUHAVEANENTITYMODELOFDbTaAND=^cT YOUCANIMPLEMENT=^cT_PSBTaeXRT WHICHWILLADD UPDATE DELETE ANDSEARCHNOTES)NTHISSECTION YOUWILLLEARNTOIMPLEMENTA7#&SERVICE9OUWILLALSO LEARNTOUSETHE%NTITY&RAMEWORKTOINTERACTWITHTHE31,!ZUREDATABASE
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
#ODINGTHE7#ONTRACT )NORDERTOCREATEA7#&SERVICE YOUMUSTFIRSTDEFINEA7#&SERVICECONTRACT)FYOUHAVEDONE EVERYTHINGSUCCESSFULLY 3OLUTION%XPLORERIN6ISUAL3TUDIOWILLRESEMBLE&IGURE
&IGURE .OTEPAD3ERVICEPROJECTIN3OLUTION%XPLORER /PEN8BTaeXRTRbANDREPLACETHECONTENTWITHTHECODETHATFOLLOWS4HE7#&CONTRACTWILL CONTAINMETHODSTOADD DELETE UPDATE ANDSEARCHNOTESIN=^cT_PS314HENAMESPACE BhbcT\BTaeXRT_TaPcX^]2^]caPRc WHICH MUSTBEDEFINEDINORDERTOCREATEA7#&SERVICE dbX]VBhbcT\BTaeXRT_TaPcX^]2^]caPRcL 6dXS0SSDbTa6dXSdbTa8SbcaX]VdbTa=P\T* J>_TaPcX^]2^]caPRcL =^cT3c^0SS=^cT6dXSdbTa8SbcaX]V]^cTSTbRaX_cX^]bcaX]V]^cTCTgc* J>_TaPcX^]2^]caPRcL E^XSD_SPcT=^cTX]c]^cT8SbcaX]V]^cTCTgc*
#(!04%2 "5),$).'7).$/730(/.%!00,)#!4)/.353).'#,/5$3%26)#%3!3$!4!34/2%3
J>_TaPcX^]2^]caPRcL e^XS3T[TcT=^cT6dXSdbTa8SX]c]^cT8S* J>_TaPcX^]2^]caPRcL ;Xbc+=^cT3c^-6Tc=^cTb6dXSdbTa8S* J>_TaPcX^]2^]caPRcL =^cT3c^6Tc=^cT6dXSdbTa8SX]c]^cT8S* l l )NTHENEXTSECTION YOUWILLCREATEADATACONTRACTTHATWILLBESENTTOTHECLIENTTHROUGHTHESERVICE
#ODINGTHE$ATA#ONTRACT "EFOREYOUIMPLEMENTTHESERVICECONTRACT YOUWILLNEEDTODEFINETWODATATRANSFEROBJECTSTOMAPTO THEENTITYOBJECT!LTHOUGHYOUCANEXPOSETHEENTITYGENERATEDBYTHE%NTITY&RAMEWORKDIRECTLYTOTHE 7#&SERVICE ITISNOTARECOMMENDEDPRACTICEBECAUSETHE%NTITY&RAMEWORKEXPOSESINFORMATIONNOT NECESSARYFORTHECLIENT&OREXAMPLE CERTAINTYPESOFINFORMATION SUCHASFOREIGNKEYS PRIMARYKEYS ANDANY%NTITY&RAMEWORKnRELATEDINFORMATION HAVENOMEANINGTOTHECLIENT!LSO WHENTHE%NTITY &RAMEWORKOBJECTISSERIALIZED ITWILLINCLUDEALLTHISUNNECESSARYINFORMATION CAUSINGTHESERIALIZED OBJECTSCOMINGTHROUGHTHE)NTERNETTOBECOMEHUGE3INCEYOUAREWORKINGWITH7INDOWS0HONEOVER WIRELESSOR7I &ITRANSMISSION YOUWILLWANTTOKEEPTHEAMOUNTOFINFORMATIONSENTTOAMINIMUM
!DDTHEDbTa3c^RbCLASSTO=^cT_PSBTaeXRTA^[TVIATHEFOLLOWINGCODE4HE NAMESPACEYOUWILLBEUSING BhbcT\Ad]cX\TBTaXP[XiPcX^] LETSYOUADD 3PcP2^]caPRcAND3PcP8b^[PcTSBc^aPVT* dbX]VBhbcT\2^\_^]T]cQYTRc