PUBLISHED BY
Microsoft Press
A Division of Microsoft Corporation
One Microsoft Way
Redmond, Washington 98052-6399
Copyright © 2010 by Microsoft Corporation
All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means
without the written permission of the publisher.
Library of Congress Control Number: 2010939982
ISBN: 978-0-7356-4335-2
Printed and bound in the United States of America.
Microsoft Press books are available through booksellers and distributors worldwide. For further information about
international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at
fax (425) 936-7329. Tell us what you think of this book at http://www.microsoft.com/learning/booksurvey.
Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/Trademark/EM-
US.aspx are trademarks of the Microsoft group of companies. All other marks are the property of their respective owners.
The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events
depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail address,
logo, person, place, or event is intended or should be inferred.
This book expresses the author’s views and opinions. The information contained in this book is provided without any
express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will
be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.
Developmental and Project Editor: Devon Musgrave
Editorial Production: Ashley Schneider, S4Carlisle Publishing Services
Technical Reviewer: Per Blomqvist; Technical Review Services provided by Content Master, a member of CM Group,
Ltd.
Cover: Tom Draper Design
Body Part No. X17-12906
iii
Contents at a Glance
Part I The Basics
1 Hello, Windows Phone 7 .............................................................. 2
Part II Silverlight
2 Getting Oriented.......................................................................... 29
3 An Introduction to Touch........................................................... 47
4 Bitmaps, Also Known as Textures ............................................. 62
5 Sensors and Services ................................................................... 80
6 Issues in Application Architecture ...........................................103
7 XAML Power and Limitations................................................... 138
8 Elements and Properties........................................................... 165
9 The Intricacies of Layout ..........................................................192
10 The App Bar and Controls ........................................................ 232
11 Dependency Properties ............................................................. 296
12 Data Bindings .............................................................................338
13 Vector Graphics .......................................................................... 393
14 Raster Graphics ..........................................................................461
15 Animations ................................................................................. 508
16 The Two Templates ...................................................................578
17 Items Controls ............................................................................641
18 Pivot and Panorama ..................................................................712
iv
Part III XNA
19 Principles of Movement ............................................................ 750
20 Textures and Sprites.................................................................. 775
21 Dynamic Textures ......................................................................799
22 From Gestures to Transforms ..................................................840
23 Touch and Play...........................................................................900
24 Tilt and Play ...............................................................................952
v
Table of Contents
Introduction ................................................................................. xii
Part I The Basics
1 Hello, Windows Phone 7............................................................... 2
Targeting Windows Phone 7 ...........................................................................2
The Hardware Chassis ......................................................................................4
Sensors and Services ........................................................................................6
File | New | Project ...........................................................................................7
A First Silverlight Phone Program ..................................................................8
The Standard Silverlight Files ........................................................................10
Color Themes ..................................................................................................17
Points and Pixels.............................................................................................18
The XAP is a ZIP..............................................................................................20
An XNA Program for the Phone ...................................................................21
2 Getting Oriented.......................................................................... 29
Silverlight and Dynamic Layout ....................................................................29
Orientation Events ..........................................................................................36
XNA Orientation .............................................................................................38
Simple Clocks (Very Simple Clocks)..............................................................41
3 An Introduction to Touch ........................................................... 47
Low-Level Touch Handling in XNA...............................................................47
The XNA Gesture Interface ............................................................................51
Low-Level Touch Events in Silverlight..........................................................52
The Manipulation Events ...............................................................................56
Routed Events .................................................................................................59
Some Odd Behavior? ......................................................................................61
4 Bitmaps, Also Known as Textures.............................................. 62
XNA Texture Drawing ....................................................................................63
The Silverlight Image Element ......................................................................65
Images Via the Web .......................................................................................66
Image and ImageSource ................................................................................70
Loading Local Bitmaps from Code ................................................................71
vi