Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tài liệu Beginning Windows Phone 7 Development pptx
PREMIUM
Số trang
481
Kích thước
18.6 MB
Định dạng
PDF
Lượt xem
1525

Tài liệu Beginning Windows Phone 7 Development pptx

Nội dung xem thử

Mô tả chi tiết

Start developing applications

for the Windows Phone quickly and easily

Beginning

Windows Phone 7

Development

Henry Lee | Eugene Chuvyrov

Start developing applications

for the Windows Phone quickly and easily

Beginning

Windows Phone 7

Development

Henry Lee | Eugene Chuvyrov

Start developing applications

for the Windows Phone quickly and easily

Beginning

Windows Phone 7

Development

Henry Lee | Eugene Chuvyrov

Start developing applications

for the Windows Phone quickly and easily

Beginning

Windows Phone 7

Development

Henry Lee | Eugene Chuvyrov

Start developing applications

for the Windows Phone quickly and easily

Beginning

Windows Phone 7

Development

Henry Lee | Eugene Chuvyrov

Start developing applications

for the Windows Phone quickly and easily

Beginning

Windows Phone 7

Development

Henry Lee | Eugene Chuvyrov

Start developing applications

for the Windows Phone quickly and easily

Beginning

Windows Phone 7

Development

Henry Lee | Eugene Chuvyrov

Start developing applications

for the Windows Phone quickly and easily

Beginning

Windows Phone 7

Development

Henry Lee | Eugene Chuvyrov

Download from Wow! eBook <www.wowebook.com>

i

Beginning Windows

Phone 7 Development

■ ■ ■

Henry Lee

and

Eugene Chuvyrov

ii

Beginning Windows Phone 7 Development

Copyright © 2010 by Henry Lee & Eugene Chuvyrov

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-3216-2

ISBN-13 (electronic): 978-1-4302-3217-9

Printed and bound in the United States of America 9 8 7 6 5 4 3 2 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

Development Editor: John Osborn

Technical Reviewer: Stefan Turalski

Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick,

Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank

Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh

Coordinating Editor: Jennifer L. Blackwell

Copy Editor: Mary Ann Fugate

Compositor: MacPS, LLC

Indexer: Brenda Miller

Artist: April Milne

Cover Designer: Anna Ishchenko

Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th

Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer￾sbm.com, 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/info/bulksales.

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.

The source code for this book is available to readers at www.apress.com.

iii

To Erica, my beautiful wife, for her love and support.

Thank you for always being there for me.

—Henry Lee

To Marianna—my friend, my wife, my muse—and to

my parents for their gift of unconditional love.

—Eugene Chuvyrov

iv

Contents at a Glance

■Contents ................................................................................................................v

■About the Authors .............................................................................................. xvi

■About the Technical Reviewer........................................................................... xvii

■Acknowledgments............................................................................................ xviii

■Introduction ....................................................................................................... xix

Part 1: The Essentials of Windows Phone 7 Application Development ....................1

■Chapter 1: Introducing Windows Phone 7 and the Windows Phone Platform.......3

■Chapter 2: Building Windows Phone 7 Applications ...........................................15

■Chapter 3: Using Cloud Services As Data Stores.................................................35

■Chapter 4: Catching and Debugging Errors.........................................................97

■Chapter 5: Packaging, Publishing, and Managing Applications .......................121

Part 2: Using Windows Phone 7 Technologies .....................................................139

■Chapter 6: Working with the Accelerometer.....................................................141

■Chapter 7: Application Bar ................................................................................161

■Chapter 8: WebBrowser Control........................................................................179

■Chapter 9: Working with Controls and Themes..................................................193

■Chapter 10: Integrating Applications with the Windows Phone OS ..................211

■Chapter 11: Creating Trial Applications ............................................................229

■Chapter 12: Internationalization .......................................................................251

■Chapter 13: Isolated Storage.............................................................................267

■Chapter 14: Using Location Services.................................................................285

■Chapter 15: Media.............................................................................................311

■Chapter 16: Working with the Camera and Photos ...........................................329

■Chapter 17: Push Notifications..........................................................................347

■Chapter 18: Reactive Extensions for .NET .........................................................383

■Chapter 19: Security .........................................................................................413

■Index .................................................................................................................441

v

Contents

■Contents at a Glance ............................................................................................iv

■About the Authors .............................................................................................. xvi

■About the Technical Reviewer........................................................................... xvii

■Acknowledgments............................................................................................ xviii

■Introduction........................................................................................................ xix

Part 1: The Essentials of Windows Phone 7 Application Development ....................1

■Chapter 1: Introducing Windows Phone 7 and the

Windows Phone Platform ....................................................................3

Windows Phone Overview............................................................................................... 5

Windows Phone Hardware Specifications ...................................................................... 5

Windows Phone Application Platform............................................................................. 7

Silverlight for Windows Phone ...............................................................................................................7

XNA for Windows Phone ........................................................................................................................8

Tools.......................................................................................................................................................8

Cloud Services .....................................................................................................................................11

Metro Design........................................................................................................................................12

Application Development Life Cycle.............................................................................. 12

Summary....................................................................................................................... 14

■Chapter 2: Building Windows Phone 7 Applications ...........................................15

Preparing Your Development Machine.......................................................................... 15

Building Your First Windows Phone 7 Application ........................................................ 15

Creating a Windows Phone Project......................................................................................................16

■ CONTENTS

vi

Using Your First Windows Phone Silverlight Controls..........................................................................18

Writing Your First Windows Phone Code..............................................................................................22

Running Your First Silverlight Windows Phone Application .................................................................23

Customizing Your First Windows Phone Application............................................................................25

Styling Your Application.......................................................................................................................28

Summary....................................................................................................................... 34

■Chapter 3: Using Cloud Services As Data Stores.................................................35

Introducing the MVVM Pattern ...................................................................................... 36

Introducing Microsoft Azure and SQL Azure ................................................................. 37

Creating a Cloud Database............................................................................................ 37

Creating an SQL Azure Database .........................................................................................................38

Creating a Database in SQL Azure .......................................................................................................47

Creating a Cloud Service to Access the Cloud Database .............................................. 50

Creating a Windows Azure Project.......................................................................................................51

Generating an Object Model to Access the Cloud Database ................................................................52

Implementing a WCF Service to Access the SQL Azure Database .......................................................57

Building a Phone Client to Access a Cloud Service....................................................... 64

Creating a Windows Phone Project......................................................................................................64

Building the User Interface ..................................................................................................................65

Coding MainPage .................................................................................................................................71

Coding the BoolToVisibilityConvert ......................................................................................................72

Adding Reference to NotepadService ..................................................................................................74

Coding NotepadViewModel ..................................................................................................................75

Testing the Application Against NotepadService Deployed Locally .....................................................82

Deploying the Service to Windows Azure ............................................................................................83

Testing the Notepad Application Against NotepadService Azure Service............................................94

Summary....................................................................................................................... 95

■Chapter 4: Catching and Debugging Errors.........................................................97

Debugging Application Exceptions................................................................................ 97

Debugging Page Load Exceptions........................................................................................................98

■ CONTENTS

vii

Debugging a Web Service Exception .................................................................................................102

Testing the Application ......................................................................................................................107

Registering a Windows Phone Device for Debugging................................................. 107

Handling Device Exceptions........................................................................................ 113

Creating the CatchDeviceExceptionDemo Project..............................................................................114

Building the User Interface ................................................................................................................115

Coding the Application .......................................................................................................................117

Testing the Finished Application........................................................................................................119

Summary..................................................................................................................... 119

■Chapter 5: Packaging, Publishing, and Managing Applications .......................121

Windows Phone Application Publishing Lifecycle....................................................... 121

Windows Phone Application Certification Requirements............................................ 123

Application Policies............................................................................................................................123

Content Policies .................................................................................................................................125

Application Submission Validation Requirements..............................................................................125

Application Certification Requirements..............................................................................................126

Submitting Your First Windows Phone Application to

the Windows Phone Marketplace ........................................................................ 128

Package the application.....................................................................................................................128

Submit the application.......................................................................................................................129

Updating your application ..................................................................................................................136

Finding your application in the Marketplace......................................................................................137

Summary..................................................................................................................... 138

Part 2: Using Windows Phone 7 Technologies .....................................................139

■Chapter 6: Working with the Accelerometer.....................................................141

Understanding Orientation and Movement ................................................................. 141

Calculating Distance ..........................................................................................................................144

Calculating Pitch and Roll ..................................................................................................................144

Introducing SDK Support for Accelerometers ............................................................. 146

■ CONTENTS

viii

Retrieving Accelerometer Data ................................................................................... 146

Creating the CaptureAccelerometerData Project ...............................................................................147

Building the User Interface ................................................................................................................148

Coding the Application .......................................................................................................................150

Testing the Finished Application........................................................................................................152

Using Accelerometer Data to Move a Ball................................................................... 153

Creating the MoveBall Project............................................................................................................154

Building the User Interface ................................................................................................................155

Coding the Application .......................................................................................................................157

Testing the Finished Application........................................................................................................159

Summary..................................................................................................................... 159

■Chapter 7: Application Bar ................................................................................161

Introducing the Application Bar .................................................................................. 162

Adding an Application Bar to a Windows Phone 7 Application ................................... 163

Adding Images for Use with Application Bar Buttons ........................................................................164

Adding a Global Application Bar Using XAML.....................................................................................166

Adding a Local Application Bar Using XAML ......................................................................................167

Adding Menu Items ............................................................................................................................168

Adding an Application Bar Using Managed Code...............................................................................169

Wiring Up Events to an Application Bar ...................................................................... 171

Adding “Glue” Code and a “Worker Function” to the Add Button......................................................171

Reacting to Add Button Events...........................................................................................................172

Reacting to Save Button Events.........................................................................................................175

Reacting to Menu Events ...................................................................................................................175

Adding Event Handlers with XAML.....................................................................................................176

Summary..................................................................................................................... 177

■Chapter 8: WebBrowser Control........................................................................179

Introducing the WebBrowser Control.......................................................................... 179

Adding a WebBrowser Control .................................................................................... 180

■ CONTENTS

ix

Using a WebBrowser Control to Display Web Content ................................................ 181

Using a WebBrowser Control to Display Local HTML Content..................................... 183

Using a WebBrowser Control to Display Dynamic Content ......................................... 185

Saving Web Pages Locally .......................................................................................... 187

Choosing Display and Security Settings ..................................................................... 188

Viewport................................................................................................................... 188

CSS.....................................................................................................................................................189

Security..............................................................................................................................................190

Summary..................................................................................................................... 191

■Chapter 9: Working with Controls and Themes..................................................193

Introducing the Metro Design System......................................................................... 193

Windows Phone Chrome ....................................................................................................................194

Screen Orientations ...........................................................................................................................195

Themes on Windows Phone 7 Devices ....................................................................... 196

Applying a Theme ..............................................................................................................................196

Changing the Theme..........................................................................................................................198

Detecting the Currently Selected Theme ...........................................................................................200

Panorama and Pivot Controls...................................................................................... 201

Using the Panorama Control ..............................................................................................................201

Using the Pivot Control.......................................................................................................................205

Understanding Frame and Page Navigation................................................................ 205

Creating a User Interface for NavigationTest Project.........................................................................206

Adding Navigation Code.....................................................................................................................206

Adding Code to Pass Parameters Between Pages .............................................................................207

Adding Transition Effects............................................................................................ 207

Creating a User Interface ...................................................................................................................207

Downloading TiltEffect.cs and Applying Dependency Properties.......................................................209

Summary..................................................................................................................... 210

■ CONTENTS

x

■Chapter 10: Integrating Applications with the Windows Phone OS ..................211

Introducing Windows Phone 7 Launchers and Choosers. .......................................... 211

Launchers . .........................................................................................................................................212

Choosers . ...........................................................................................................................................213

Working with Launchers and Choosers . .................................................................... 213

Creating the User Interface . ...............................................................................................................213

Coding Application Logic. ...................................................................................................................214

Working with the Windows Phone 7 Application Life Cycle. ...................................... 215

Observing Application Life Cycle Events . ...........................................................................................216

Managing Application State . ..............................................................................................................220

Best Practices for Managing the Application Life Cycle on the Windows Phone 7 OS ......................225

Windows Phone 7 Hubs . ............................................................................................ 225

Summary. ................................................................................................................... 227

■Chapter 11: Creating Trial Applications ............................................................229

Understanding Trial and Full Modes ........................................................................... 229

Using the IsTrial Method . ...................................................................................................................230

Using the Marketplace APIs . ..............................................................................................................231

Simulating Application Trial and Full Modes. .....................................................................................234

Building a Trial Application . ....................................................................................... 237

Building the User Interface . ...............................................................................................................238

Connecting to a Web Service . ............................................................................................................242

Adding Page-to-Page Navigation . ......................................................................................................244

Verifying Trial and Full Mode . ............................................................................................................246

Adding Finishing Touches . .................................................................................................................247

Summary. ................................................................................................................... 249

■Chapter 12: Internationalization .......................................................................251

Understanding Internationalization............................................................................. 251

Using Culture Settings with ToString to Display Dates, Times, and Text. .................. 252

Using the .NET Culture Hierarchy to Ensure Culture Neutrality. ................................. 254

Download from Wow! eBook <www.wowebook.com>

■ CONTENTS

xi

Storing and Retrieving Current Culture Settings......................................................... 256

Using Resource Files to Localize Content ................................................................... 260

Summary..................................................................................................................... 265

■Chapter 13: Isolated Storage.............................................................................267

Working with Isolated Directory Storage .................................................................... 268

Creating the IsolatedStorageStoreImageDemo Project......................................................................269

Coding the User Interface ..................................................................................................................270

Coding the Application .......................................................................................................................272

Working with Isolated Storage Settings...................................................................... 276

Creating a New Project ......................................................................................................................277

Building the Application UI (XAML).....................................................................................................278

Coding Application Behavior (C#).......................................................................................................281

Summary..................................................................................................................... 283

■Chapter 14: Using Location Services.................................................................285

Understanding Windows Phone Location Services Architecture ................................ 285

Introducing the Windows Phone Location Service and Mapping APIs........................ 286

Simulating the Location Service ................................................................................. 286

Creating the GeoCoordinateWatcherDemo Project ............................................................................287

Coding the User Interface ..................................................................................................................288

Coding the Application .......................................................................................................................290

Testing the Finished Application........................................................................................................292

Using GeoCoordinateWatcher and the Bing Maps Control to Track Your Movements 292

Registering with the Bing Maps Service Portal and Installing the Bing Maps SDK............................293

Creating the BingMapDemo Project...................................................................................................295

Coding the User Interface ..................................................................................................................297

Coding the Application .......................................................................................................................299

Testing the Finished Application........................................................................................................302

Plotting an Address on a Bing Maps Map and Working with the Bing Maps Service . 303

Creating the AddressPlottingDemo Application .................................................................................304

■ CONTENTS

xii

Adding a Service Reference to the Bing Maps GeoCodeService........................................................304

Coding the User Interface ..................................................................................................................306

Coding the Application .......................................................................................................................308

Testing the Finished Application........................................................................................................310

Summary..................................................................................................................... 310

■Chapter 15: Media.............................................................................................311

Introducing MediaElement.......................................................................................... 311

Working with Video..................................................................................................... 312

Creating the MediaPlayerDemo Project .............................................................................................313

Building the User Interface ................................................................................................................314

Coding the Application .......................................................................................................................317

Adding Sounds to an Application ................................................................................ 322

Creating the RobotSoundDemo Project..............................................................................................323

Building the User Interface ................................................................................................................324

Coding the Application .......................................................................................................................327

Summary..................................................................................................................... 328

■Chapter 16: Working with the Camera and Photos ...........................................329

Introducing Windows Phone 7 Photo Features ........................................................... 329

Using a Chooser to Take Photos ........................................................................................................331

Using a Chooser to Open Photos........................................................................................................334

Saving Photos to the Phone ...............................................................................................................336

Integrating Your Application with Windows Phone 7 .................................................. 338

Using Extras to Launch an Application...............................................................................................338

Using Share to Upload PhotoCapture Snapshots to TwitPic ..............................................................340

Summary..................................................................................................................... 347

■Chapter 17: Push Notifications..........................................................................347

Understanding Push Notifications............................................................................... 347

Toast Notifications .............................................................................................................................347

Tile Notifications ................................................................................................................................348

■ CONTENTS

xiii

Raw Notifications...............................................................................................................................349

Introducing the Push Notifications Architecture ......................................................... 349

The Life Cycle of a Notification ..........................................................................................................350

The Push Notification Framework......................................................................................................352

Implementing Toast Notifications ............................................................................... 353

Creating a Client Application..............................................................................................................353

Creating an Application to Send Notifications....................................................................................358

Implementing Tile Notifications .................................................................................. 363

Creating a Client Application..............................................................................................................364

Creating an Application to Send Notifications....................................................................................364

Implementing Raw Notifications................................................................................. 367

Creating a Client Application..............................................................................................................368

Creating an Application to Send Notifications....................................................................................371

Testing Delivery of Raw Notifications ................................................................................................372

Implementing Cloud Service to Track Push Notifications ........................................... 372

Creating a WCF Service to Track Notification Recipients...................................................................373

Modifying the Client to Call the WCF Service.....................................................................................378

Verifying Automated Push Notification Subscriber Tracking .............................................................380

Using Push Notifications in the Real World................................................................. 381

Summary..................................................................................................................... 381

■Chapter 18: Reactive Extensions for .NET .........................................................383

Introducing Reactive Programming ............................................................................ 384

Implementing the Observer Pattern with Rx.NET........................................................ 386

Creating a Windows Phone Project....................................................................................................386

Adding Code to Create and Read Observable Collections..................................................................386

Using Rx.NET Event Handling to Search for Flickr Photographs................................. 388

Creating a Windows Phone Project....................................................................................................389

Adding a User Interface......................................................................................................................390

Adding Logic to Search Flickr for Images ..........................................................................................390

Tải ngay đi em, còn do dự, trời tối mất!