Essential Windows Phone 7.5
Application Development with Silverlight
Shawn Wildermuth
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Capetown Sydney Tokyo Singapore Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The .NET logo is either a registered trademark or trademark of Microsoft Corporation in the United States and/or other countries and is used under license from Microsoft.
Microsoft, Windows, Visual Basic, Visual C#, and Visual C++ are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries/regions.
The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
For sales outside the United States, please contact:
International Sales
Visit us on the Web: informit.com/aw
Library of Congress Cataloging-in-Publication Data
Wildermuth, Shawn.
Essential windows phone 7.5 : application development with silverlight
/ Shawn Wildermuth.
p. cm.
Includes index.
ISBN 978-0-321-75213-0 (pbk. : alk. paper)
1. Windows phone (Computer file) 2. Silverlight (Electronic resource)
3. Operating systems (Computers) 4. Application softwareDevelopment.
5. Mobile computingProgramming. I. Title.
QA76.59.W54 2012
005.4'46dc23
2011036842
Copyright 2012 Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290.
ISBN-13: 978-0-321-75213-0
ISBN-10: 0-321-75213-9
Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana.
First printing, December 2011
To my friend and mentor, Chris Sells, without whom I would have never learned that the story is more important than the facts.
Figures
33
TextBox
control example90
PhoneTextBox
s length indication support135
168
201
351
Tables
207
Foreword
When Shawn asked me to write a foreword for his Windows Phone development book, I had a couple of reactions. First, that they must really be scraping the bottom of the barrel if they have asked me to write anything. There are so many people who actually help bring the product to market who never really get the credit they deserve. While I am honored that I was asked to write this, based in part on my public role on the team, the engineering team that designed and built this amazing product are the real heroes. The product itself is amazing, but the right application platform, which enables the amazing Metro apps and games to be built, is a developers playground. I do this to honor them.
My second reaction was to think about the huge value Shawn has in the Microsoft ecosystem. As an eight-time MVP and Silverlight Insider, Shawns contributions are highly valued both for their content as well as for their reach. When Shawn speaks, you know that he has the developer in mind: He is a developers developer. Without individuals like Shawn, it would be tough (if possible at all) for Microsoft to have built our developer ecosystem over the last three decades. I do this to honor him.
My last reaction was one of panic. I have never written a foreword before, so I was at a bit of a loss as to what I should say. I figure if you are buying this book, you did so of your own volition, and not on the strength of what I have to say here. However, if you are reading the foreword with an eye toward confirming your belief that Windows Phone is where its at, well, for that I can be accommodating. I do this to honor you.
With the initial release of Windows Phone, and the subsequent pairing with Nokia, Microsoft is investing in building the third ecosystem for mobile developers. The canvas with which mobile developers can work on Windows Phone is unlike any other platform, whereby developers can create simply gorgeous apps with more focus on the user experience than tinkering with the innards of a convoluted framework. Metro apps come alive on the screen, and you will be able to build deeply engaging applications using Live Tiles.
Windows Phone 7.5 is an updated release, codenamed Mango, and carries with it the tagline Put people first. We think the same way about the developer platform. We aim to put developers first. The book you are holding might be your first step on your journey to building Windows Phone apps. It may be a refresher course. Either way, with Shawns guidance, we know that you will come away from this experience feeling great about your prospects of building amazing mobile experiences for Windows Phone, and a firm belief that Microsoft puts the developers first when we think about Windows Phone. Every developer matters. Every. Single. One.
Brandon Watson
Microsoft Corporation
Preface
I have never owned a PalmPilot. But I have owned palmtops and smartphones. I dived into writing software for a plethora of different devices but never got very far. My problem was that the story of getting software onto the phones was chaotic and I didnt see how the marketing of software for phones would lead to a successful product. In the intervening years, I got distracted by Silverlight and Web development. I didnt pay attention as the smartphone revolution happened. I was happily neck-deep in data binding, business application development, and teaching XAML.
The smartphone revolution clearly started with the iPhone. What I find interesting is that the iPhone is really about the App Store, not the phone. Its a great device, but the App Store is what changed everything, providing a simple way to publish, market, and monetize applications for these handheld powerhouses that everyone wanted. Of course, Apple didnt mean to do it. When the original iPhone shipped, Apple clearly said that Safari (its Web browser) was the development environment. With the pressure of its OS X developer community, Apple relented and somewhat accidentally created the app revolution.
When it was clear that I had missed something, I dived headlong into looking at development for phones again. I had an Android phone at the time, so that is where I started. Getting up to speed with Eclipse and Java wasnt too hard, but developing for the phone was still a bit of a chore. The development tools just didnt seem to be as easy as the development I was used to with Visual Studio and Blend. In this same time frame, I grabbed a Mac and tried my hand at Objective-C and Xcode to write something simple for the iPhone. That experience left me bloodied and bandaged. I wanted to write apps, but since it was a side effort, the friction of the tool sets for Android and iPhone left me wanting, and I put them aside.