www.dbebooks.com - Free Books & magazineswww.it-ebooks.info www.it-ebooks.info Professional Silverlight 2 for ASP.NET Developers Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxi Part I: Silverlight Fundamentals for ASP.NET Developers 1 Chapter 1: Silverlight in a Nutshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter 2: Silverlight Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Chapter 3: XAML Condensed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Chapter 4: Programming Silverlight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Part II: Developing ASP.NET Applications with Silverlight 119 Chapter 5: Creating the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Chapter 6: Silverlight Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Chapter 7: Styles and Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Chapter 8: User Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Chapter 9: Communicating with the Server . . . . . . . . . . . . . . . . . . . . . . . . . 285 Chapter 10: Working with Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 Chapter 11: Creating Custom Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 Chapter 12: Securing Your Silverlight Application . . . . . . . . . . . . . . . . . . . . 461 Chapter 13: Audio and Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481 Chapter 14: Graphics and Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515 Chapter 15: Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559 Chapter 16: Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621 77751ffirs.indd 1 12/19/08 8:35:59 AM www.it-ebooks.info 77751ffirs.indd 2 12/19/08 8:35:59 AM www.it-ebooks.info Professional Silverlight™ 2 for ASP.NET Developers 77751ffirs.indd 3 12/19/08 8:35:59 AM www.it-ebooks.info 77751ffirs.indd 4 12/19/08 8:35:59 AM www.it-ebooks.info Professional Silverlight™ 2 for ASP.NET Developers Jonathan Swift Chris Barker Dan Wahlin Salvador Alvarez Patuel 77751ffirs.indd 5 12/19/08 8:35:59 AM www.it-ebooks.info Professional Silverlight™ 2 for ASP.NET Developers Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-27775-1 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data is available from the publisher. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permis- sion of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at www.wiley.com/ go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or war- ranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or dis- appeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Silverlight is a trade- mark of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. 77751ffirs.indd 6 12/19/08 8:35:59 AM www.it-ebooks.info To my wife, Fay. — Jonathan Swift In memory of Patricia Barker. — Chris Barker I thank my wife, Heedy, and two boys, Danny and Jeffery, for their patience, love, and support while I was working on this book. — Dan Wahlin Dedicado a Marta y a mi familia. — Salvador Alvarez Patuel 77751ffirs.indd 7 12/19/08 8:35:59 AM www.it-ebooks.info About the Authors Jonathan Swift worked as an Application Development Consultant for Microsoft in the United Kingdom for a number of years and now finds himself managing the team. This means that he spends most of his time traveling around the country helping clients utilize Microsoft developer technologies effectively. Jonathan has been programming for more than 13 years and has worked with numerous technologies, including but not limited to C, C++, Visual Basic, COM, COM+, SQL, ASP, and, of course, all aspects of .NET. As well as programming, Jonathan also spent part of his career working as a Microsoft Trainer, delivering the full suite of Microsoft Official Curriculum courses and specially-designed courses also. Jonathan tries to keep his blog (http://blogs.msdn.com/jonathanswift) up to date, but feels that writing a book is a very good excuse for not doing so. (Other popular excuses including playing the XBox and washing his hair.) When he’s not working, Jonathan spends all of his time with his wife and kids, and occasionally gets to exercise his pilot’s license at the flying club. Chris Barker works as an Application Development Consultant for Microsoft in the United Kingdom (www.microsoft.com/uk/adc). He spends his days traveling around the country visiting customers and consulting on development practices on the Microsoft platform. More recently, his interest has been captured by RIA development, and as a result, he has delivered several customer workshops on Silverlight. Away from the office, Chris likes to get out and about in his home county of Derbyshire, riding a bike, kicking a football, and sinking a few pints of real ale. Dan Wahlin (Microsoft Most Valuable Professional for Connected Systems) is a .NET development instructor and architecture consultant at Interface Technical Training (www.interfacett.com). Dan founded the XML for ASP.NET Developers web site (www.xmlforasp.net), which focuses on using ASP.NET, Silverlight, AJAX, and XML Web Services in Microsoft’s .NET platform. He’s also on the INETA Speaker’s Bureau and speaks at several conferences. Dan has authored/co-authored numerous books over the years on .NET technologies with his latest being Professional ASP.NET 3.5 AJAX and Professional Silverlight 2 for ASP.NET Developers. Dan also writes for several online technical newslet- ters, blogs at http://weblogs.asp.net/dwahlin, and updates what he’s up to from time to time at www.twitter.com/danwahlin. When he’s not working with technology, he enjoys sports and writ- ing and recording music to relax a little — http://weblogs.asp.net/dwahlin/archive/tags/ Music/default.aspx. Salvador Alvarez Patuel has been in the industry for more than 13 years. Currently a senior application development consultant (ADC) at Microsoft, helping customers to architect and build complex solutions using Microsoft technologies in the United Kingdom. Salvador has also been delivering multiple tech- nical sessions around EMEA on Windows Mobile development and has been answering questions on many ask-the-experts events. Before joining Microsoft, he was the main technical architect for real-time engines on popular auctions, TV channels, and the gaming industry. He holds a software engineering degree from his native Argentina and a specialization in artificial intelligence. When Salva is not think- ing about ones and zeroes, he enjoys climbing, windsurfing, and recently trying to learn how to play golf. 77751ffirs.indd 8 12/19/08 8:35:59 AM www.it-ebooks.info Credits Executive Editor Vice President and Executive Group Publisher Robert Elliott Richard Swadley Development Editor Vice President and Executive Publisher Kelly Talbot Joseph B. Wikert Technical Editor Project Coordinator, Cover Dave Friedel Lynsey Stanford Senior Production Editor Compositor Debra Banninger James D. Kramer, Happenstance Type-O-Rama Copy Editor Proofreader Cate Caffrey Publication Services, Inc. Editorial Manager Indexer Mary Beth Wakefield Jack Lewis Production Manager Tim Tate 77751ffirs.indd 9 12/19/08 8:35:59 AM