www.dbebooks.com - Free Books & magazines 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 Robert Elliott Development Editor Kelly Talbot Technical Editor Dave Friedel Senior Production Editor Debra Banninger Copy Editor Cate Caffrey Editorial Manager Mary Beth Wakefield Production Manager Tim Tate Vice President and Executive Group Publisher Richard Swadley Vice President and Executive Publisher Joseph B. Wikert Project Coordinator, Cover Lynsey Stanford Compositor James D. Kramer, Happenstance Type-O-Rama Proofreader Publication Services, Inc. Indexer Jack Lewis 77751ffirs.indd 9 12/19/08 8:35:59 AM www.it-ebooks.info [...]... Integrating with ASP.NET Using the ASP.NET Profile Provider ImplicitStyleManager Summary Chapter 8: User Interaction 198 199 20 0 20 2 20 3 20 5 20 6 20 7 20 8 21 0 21 2 21 3 21 3 21 4 21 8 22 4 22 4 23 2 23 5 23 5 23 9 24 2 24 3 The Silverlight Interaction Context 24 3 Working with UIElements Events Interacting with Input Devices Getting the Most from Input Devices 24 4 25 0 25 8 Navigation Silverlight Navigation in the ASP.NET World... Architecture 12 Presentation Core NET Framework Installed Files 13 16 23 ASP.NET Integration 24 ASP.NET Composite Controls Using ASP.NET Application Services Communicating with ASP.NET from Silverlight Dynamic Generation of XAML from the Server Using the ASP.NET Server Controls for Silverlight Application Life Cycle Updating Silverlight Summary 77751ftoc.indd 13 25 25 26 26 27 27 28 29 12/ 18/08 9:58:18... P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books To read the FAQs, click the FAQ link on any P2P page xxvii 77751flast.indd 27 12/ 18/08 9:57: 52 AM www.it-ebooks.info 77751flast.indd 28 12/ 18/08 9:57: 52 AM www.it-ebooks.info Part I: Silverlight Fundamentals for ASP.NET Developers Chapter 1: Silverlight. .. That All? Data-Binding Essentials 28 6 28 8 28 9 29 0 29 1 29 2 29 2 301 304 304 308 310 310 314 328 3 32 337 347 359 361 3 62 363 364 365 Binding 101 Binding in Practice Conversions Dependency Properties Performance Considerations 366 370 3 82 384 386 Retrieving and Storing Data 387 Working with Data Repositories Caching Data Controls 387 401 401 Data Templates DataGrid 4 02 403 Manipulating Data 407 Traditional... with the Server 26 6 26 6 26 7 28 0 28 3 28 5 Silverlight Networking and Communication Features 28 5 What Type of Data Can Silverlight Access and Process? Supported Domains and URLs 28 6 28 6 xvi 77751ftoc.indd 16 12/ 18/08 9:58:18 AM www.it-ebooks.info Contents Communication Options Data-Processing Options Cross-Domain Support Flash Cross-Domain Policy Files Silverlight Cross-Domain Policy Files Creating Services for Silverlight. .. 77751ftoc.indd 14 12/ 18/08 9:58:18 AM www.it-ebooks.info Contents Part II: Developing ASP.NET Applications with Silverlight 119 Chapter 5: Creating the User Interface 121 Expression Suite — A Whirlwind Tour 121 Expression Expression Expression Expression Expression Expression Web Blend Design Media Encoder Studio 122 123 129 129 130 130 ASP.NET versus Silverlight Layout 130 Layout Options in ASP.NET Layout... Introduction xxi Part I: Silverlight Fundamentals for ASP.NET Developers 1 Chapter 1: Silverlight in a Nutshell 3 Uphill Struggle Rich Client or Web Reach? Silverlight Steps In The Impact of Silverlight on Your Existing ASP.NET Real Estate What You Should Still Do in ASP.NET The Development Environment Overview Summary Chapter 2: Silverlight Architecture Client/Server Architecture Overview Platforms 3 4 4 6 6... ASP.NET Developers Chapter 1: Silverlight in a Nutshell Chapter 2: Silverlight Architecture Chapter 3: XAML Condensed Chapter 4: Programming Silverlight 77751c01.indd 1 12/ 18/08 9:57 :26 AM www.it-ebooks.info 77751c01.indd 2 12/ 18/08 9:57 :26 AM www.it-ebooks.info 1 Silverlight in a Nutshell This chapter is intended to give you a clear overview of Silverlight with the aim of helping you differentiate it from... pose any problems for NET developers either This all adds up to an incredibly fast ramp-up time for existing NET developers once the initial setup and syntax queries have been brushed aside, and therefore a potential lower initial development cost as opposed to that for NET developers taking on Flash or Java, for instance All that is required to run Silverlight in your browser is the Silverlight plug-in,... navigate to a page hosting a Silverlight application, they will be automatically prompted to install it Because of its small size, on most user connections this will take only seconds to complete 5 77751c01.indd 5 12/ 18/08 9:57 :26 AM www.it-ebooks.info Part I: Silverlight Fundamentals for ASP.NET Developers The Impact of Silverlight on Your Existing ASP.NET Real Estate Silverlight is all about delivering . magazines 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. 11 Architecture 12 Presentation Core 13 .NET Framework 16 Installed Files 23 ASP. NET Integration 24 ASP. NET Composite Controls 25 Using ASP. NET Application Services 25 Communicating with ASP. NET from Silverlight. Inline Styles 21 4 Specifying Styles in a Central Location 21 8 Templating 22 4 ControlTemplate 22 4 TemplateBinding 23 2 Integrating with ASP. NET 23 5 Using the ASP. NET Profile Provider 23 5 ImplicitStyleManager