ebook img

Migrating to Windows Phone PDF

261 Pages·2011·6.813 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Migrating to Windows Phone

Migrating to Windows Phone Jesse Liberty Jeff Blankenburg Migrating to Windows Phone Copyright © 2012 by Jesse Liberty and Jeff Blankenburg All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-3816-4 ISBN-13 (electronic): 978-1-4302-3817-1 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. President and Publisher: Paul Manning Lead Editor: Ewan Buckingham Technical Reviewer: Damien Foggon and Fabio Claudio Ferracchiati Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, 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: Jessica Belanger Copy Editor: Kimberly Burton Compositor: Apress Production (Christine Ricketts) Indexer: SPI Global Artist: SPI Global Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, NY, 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. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. 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 http://www.apress.com/source-code/. This book is dedicated to my daughters, Robin and Rachel. —Jesse Liberty This book is dedicated to my wife, Sara, and my children Riley and Miles. Without your support and understanding, nothing would be possible. —Jeff Blankenburg Contents at a Glance Contents at a Glance ...................................................................................................... iv Contents ......................................................................................................................... v About the Authors ......................................................................................................... xii About the Technical Reviewer ..................................................................................... xiii Acknowledgments ....................................................................................................... xiv Foreword ...................................................................................................................... xv Introduction ................................................................................................................ xvii Chapter 1: Get to Work: Your First Windows Phone Program ........................................ 1 Chapter 2: Get Control: Exploring Windows Phone Controls ........................................ 21 Chapter 3: Get the Data ................................................................................................. 53 Chapter 4: Get a Life ..................................................................................................... 75 Chapter 5: Get Moving: Adding Animation to Your Apps ............................................ 105 Chapter 6: Get Moving: Adding Animation to Your Apps ............................................ 105 Chapter 7: Get a Job: Interacting with User Data ....................................................... 125 Chapter 8: Get Pushy: Using Push Notifications to Keep Your Users Up-to-Date ....... 169 Chapter 9: Get Oriented: Interacting with the Phone, Camera, GPS, and More .......... 191 Chapter 10: Get Money: Profiting from Your Applications .......................................... 217 Index ........................................................................................................................... 241 iv Contents Contents at a Glance ...................................................................................................... iv Contents ......................................................................................................................... v About the Authors ......................................................................................................... xii About the Technical Reviewer ..................................................................................... xiii Acknowledgments ....................................................................................................... xiv Foreword ...................................................................................................................... xv Introduction ................................................................................................................ xvii Chapter 1: Get to Work: Your First Windows Phone Program ........................................ 1 Creating a New Application with Visual Studio .......................................................... 2 Building the User Interface with Expression Blend .................................................... 4 Setting the Application Title ............................................................................................... 6 Adding the Calculator Buttons ........................................................................................... 7 Programming the Calculator .................................................................................... 13 Examining the Button Xaml ............................................................................................. 14 Planning Button Actions................................................................................................... 15 Connecting Button Results to the Display ........................................................................ 16 Handling the Number Buttons ......................................................................................... 17 Handling Other Buttons .................................................................................................... 18 Summary .................................................................................................................. 19 Chapter 2: Get Control: Exploring Windows Phone Controls ........................................ 21 Introducing Layout Controls ..................................................................................... 21 v ■ CONTENTS The Grid Control ............................................................................................................... 22 The Canvas Control .......................................................................................................... 24 The StackPanel Control.................................................................................................... 25 Recap ............................................................................................................................... 25 Building a Real User Interface .................................................................................. 26 Getting Started ................................................................................................................. 26 Adding Missing Controls to Your Toolbox ........................................................................ 27 Using the Panorama Control ............................................................................................ 30 Adjusting Background and Accent Colors ........................................................................ 33 Adding Images to a Page ................................................................................................. 35 Navigating Between Pages .............................................................................................. 38 Dealing with the Back Stack ............................................................................................ 42 Using TextBoxes .............................................................................................................. 43 Using the ApplicationBar ................................................................................................. 45 Summary .................................................................................................................. 52 Chapter 3: Get the Data ................................................................................................. 53 Binding Data to Controls ........................................................................................... 53 Creating the Data ............................................................................................................. 54 Creating Controls ............................................................................................................. 55 Adding DataContext ......................................................................................................... 56 ListBoxes and DataTemplates ......................................................................................... 56 Binding Data with the DataBound Template ............................................................. 57 Storing Data in Isolated Storage ............................................................................... 61 Storing Data in a Local Database ............................................................................. 63 Building the UI ................................................................................................................. 64 Accessing Local Storage ................................................................................................. 65 vi ■ CONTENTS Adding Relationships ....................................................................................................... 69 Querying the Local Database ........................................................................................... 71 Database Performance Optimization ............................................................................... 72 Summary .................................................................................................................. 73 Chapter 4: Get a Life ..................................................................................................... 75 Understanding the Application Lifecycle .................................................................. 75 Fast Application Switching ....................................................................................... 77 Managing State......................................................................................................... 78 Page State ....................................................................................................................... 78 Debugging with Tombstoning .......................................................................................... 82 Using Background Agents ........................................................................................ 82 Summary .................................................................................................................. 90 Chapter 5: Get Moving: Adding Animation to Your Apps ............................................ 105 Understanding the Lexicon of Animation ................................................................ 105 Creating a Simple Animation .................................................................................. 106 Using Expression Blend to Create a Storyboard ............................................................ 107 Calling Our Storyboard from Code ................................................................................. 114 Reusing a Storyboard .................................................................................................... 116 Creating Custom (and Distracting) Page Transitions ............................................. 118 Creating the Page Turn Animation ................................................................................. 118 Adding the Animation to Your Page Events ................................................................... 120 Summary ................................................................................................................ 123 Chapter 6: Get Moving: Adding Animation to Your Apps ............................................ 105 Understanding the Lexicon of Animation ................................................................ 105 Creating a Simple Animation .................................................................................. 106 Using Expression Blend to Create a Storyboard ............................................................ 107 vii ■ CONTENTS Calling Our Storyboard from Code ................................................................................. 114 Reusing a Storyboard .................................................................................................... 116 Creating Custom (and Distracting) Page Transitions ............................................. 118 Creating the Page Turn Animation ................................................................................. 118 Adding the Animation to Your Page Events ................................................................... 120 Summary ................................................................................................................ 123 Chapter 7: Get a Job: Interacting with User Data ....................................................... 125 Distinguishing Launchers and Choosers ................................................................ 125 Setting up a Launcher .................................................................................................... 127 Setting up a Chooser ..................................................................................................... 128 Bing Tasks .............................................................................................................. 129 BingMapsDirectionsTask ............................................................................................... 129 BingMapsTask ............................................................................................................... 130 SearchTask .................................................................................................................... 132 Camera Tasks ......................................................................................................... 133 CameraCaptureTask ...................................................................................................... 133 PhotoChooserTask ......................................................................................................... 136 Communication Tasks ............................................................................................ 138 EmailComposeTask ....................................................................................................... 139 PhoneCallTask ............................................................................................................... 141 ShareLinkTask ............................................................................................................... 142 ShareStatusTask ............................................................................................................ 144 SmsComposeTask ......................................................................................................... 145 Contacts Tasks ....................................................................................................... 147 AddressChooserTask ..................................................................................................... 147 EmailAddressChooserTask ............................................................................................ 149 viii ■ CONTENTS PhoneNumberChooserTask ........................................................................................... 150 SaveEmailAddressTask ................................................................................................. 151 SavePhoneNumberTask ................................................................................................. 151 SaveContactTask ........................................................................................................... 153 Marketplace Tasks ................................................................................................. 154 MarketplaceDetailTask .................................................................................................. 154 MarketplaceHubTask ..................................................................................................... 156 MarketplaceReviewTask ................................................................................................ 156 MarketplaceSearchTask ................................................................................................ 157 Miscellaneous Tasks .............................................................................................. 158 ConnectionSettingsTask ................................................................................................ 158 MediaPlayerLauncher .................................................................................................... 159 SaveRingtoneTask ......................................................................................................... 160 WebBrowserTask ........................................................................................................... 163 Using the Microsoft.Phone.UserData Namespace .................................................. 164 Contacts ......................................................................................................................... 164 Appointments ................................................................................................................. 166 Summary ................................................................................................................ 167 Chapter 8: Get Pushy: Using Push Notifications to Keep Your Users Up-to-Date ....... 169 Understanding Push Notifications (and the US Postal Service) .............................. 169 Creating a Notification App ..................................................................................... 170 Creating a Toast Notification .................................................................................. 173 Creating a Raw Notification .................................................................................... 179 Creating a Tile Notification ..................................................................................... 183 Live Tile Updates..................................................................................................... 186 Summary ................................................................................................................ 188 ix

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.