Tải bản đầy đủ (.pdf) (675 trang)

professional silverlight 2 for asp.net developers

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (12.08 MB, 675 trang )

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 (
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
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 —
/>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
Acknowledgments
It turns out that writing a book is a much more challenging affair than you think it’s going to be. And I
mean by a long way. For the past 18 months since this book was first conceived, there hasn’t been a single

day go by when I haven’t worried about falling behind schedule or not getting finished at all. Remember
as a kid when you had some homework to hand in or an exam to revise, and every day leading up to it
you knew you should be doing something? Well, that’s close to how taking on this book has been, but
only close!
This brings me nicely to my first acknowledgement, which is, of course, to my wife, Fay, and our two
children, Jonah and Stirling, who’ve put up with me being a little grumpier (just a little, mind …) than
usual in recent times owing in the whole to the large project that this book has been. Thanks for putting
up with me, and I hope you enjoy laughing at my picture on the front cover as much as the readers will!
Secondly, I’d like to thank the other authors in this book, quite literally without whom this book would
be, well, about half as long. Chris, for listening to endless late-night and early-morning phone calls —
usually from a train so via a poor signal — and helping me correct coding errors, I thank you. Salvador,
for stepping in at short notice and lending your Silverlight expertise to this book, as well as endearing it
to the female population via your front cover photo, I thank you. And Dan, for getting through your
chapters on schedule, providing useful hints and a professional attitude, I thank you also.
Finally, I’d like to say a big thank you to my parents, Linton and Julie, without whose collective genes I
wouldn’t have become the geek I am today. This coupled with inheriting my father’s passion for reading
Sci-Fi, of course. Ta very much!
— Jonathan Swift
Contributing to this book has been quite a journey, and I am sure that those around me have felt as
though they had been writing the book themselves! With that said, I would like to show my gratitude
by giving them a mention here. First and foremost, I would like to thank my family — David Barker,
Matt Barker, and Marie Barker. In particular, I would like to thank my late mother, Patricia Barker,
whose support in my early years is greatly missed.
— Chris Barker
I’d like to thank my wife, Heedy, and two boys, Danny and Jeffery, for putting up with the long hours I
spend in the office studying new technologies and writing books and articles. I love them and sincerely
appreciate their patience with me. I’m extremely lucky to have such a great family.
I’d also like to thank my Mom and Dad, Danny and Elaine, for bringing me up in such a positive, caring
environment where succeeding in life was always encouraged. I love both of you and am forever in your
debt for the years of service you’ve given and the many life lessons you’ve taught me.

— Dan Wahlin
77751ffirs.indd 10 12/19/08 8:35:59 AM
www.it-ebooks.info
xi
Acknowledgments
I would like to dedicate this book to my wife, Marta, for supporting and loving me. She has given me
all the strength needed to embark on this adventure. Marta, I really love you. The other big important
part of my life is my family — Graciela (ma) and Daniel (pa); my grandparents, Irene, Angel, Coca, and
Hugo; my brother Rodrigo; and my sister Macarena. I want to include them in this dedication as they
have given me all their support and love no matter how far we are from each other. To them I say: I owe
you everything. Los quiero mucho!
I want also to thank my friends Ata, Gei, Maxi, and Horacio for all the good times that we have shared
together across the distance. Also to my “local” friends Amit, Andrew, Ralf, Miguele, and Moises and
the many more that I am forgetting. Finally, a special mention to my manager Steve Leaback for all his
support.
— Salvador Alvarez Patuel
77751ffirs.indd 11 12/19/08 8:35:59 AM
www.it-ebooks.info
77751ffirs.indd 12 12/19/08 8:35:59 AM
www.it-ebooks.info
Contents
Introduction xxi
Silverlight Fundamentals for ASP.NET Developers Part I: 1
Silverlight in a Nutshell Chapter 1: 3
Uphill Struggle 3
Rich Client or Web Reach? 4
Silverlight Steps In 4
The Impact of Silverlight on Your Existing ASP.NET Real Estate 6
What You Should Still Do in ASP.NET 6
The Development Environment Overview 7

Summary 8
Silverlight Architecture Chapter 2: 9
Client/Server Architecture Overview 9
Platforms 10
The Server 11
The Client 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 26
Dynamic Generation of XAML from the Server 26
Using the ASP.NET Server Controls for Silverlight 27
Application Life Cycle 27
Updating Silverlight 28
Summary 29
77751ftoc.indd 13 12/18/08 9:58:18 AM
www.it-ebooks.info
xiv
Contents
XAML Condensed 3Chapter 3: 1
Why All ASP.NET Developers Should Know the Basics 31
XAML Syntax and Terminology 33
Namespaces 33
White Space 34
Object and Property Elements 36
Type Converters 37

Markup Extensions 38
Attached Properties 40
Basic Drawing 41
The Code-Behind 46
Dynamically Loading XAML 49
Available Tools 56
Piecing It All Together 57
Summary 61
Programming Silverlight 6Chapter 4: 3
How a Silverlight Application Is Composed 63
Packaging a Silverlight Application 64
System.Windows.Application 66
Application Instantiation 69
A Basic Silverlight Page 72
JavaScript — How Much You Need to Know 76
JavaScript — The Basics 77
Object Model 77
Adding JavaScript to a Page 77
Variable Usage 78
Functions 78
Conditional Statements 79
Handling Events 80
DOM Manipulation 80
The Silverlight Object Model 84
DependencyObject, UIElement, and FrameworkElement 84
Walking the Tree 85
Events, Threading, and Browser Interaction 90
Events 90
Threading and Asynchrony 95
Browser Interaction 105

On-Demand XAP Loading 114
System.Net.WebClient 114
Summary 116
77751ftoc.indd 14 12/18/08 9:58:18 AM
www.it-ebooks.info
xv
Contents
Developing ASP.NET Applications with Silverlight 11Part II: 9
Creating the User Interface 12Chapter 5: 1
Expression Suite — A Whirlwind Tour 121
Expression Web 122
Expression Blend 123
Expression Design 129
Expression Media 129
Expression Encoder 130
Expression Studio 130
ASP.NET versus Silverlight Layout 130
Layout Options in ASP.NET 130
Layout Options in Silverlight 131
Full-Screen Support 154
Localization 162
Summary 165
Silverlight Controls 16Chapter 6: 7
Introduction to Silverlight Controls 168
Defining Controls in XAML 169
Handling Control Events Declaratively 170
Handling Control Events Programmatically 171
User Input Controls 172
The TextBlock Control 173
The TextBox Control 174

The PasswordBox Control 176
The Button Control 176
The HyperlinkButton Control 177
The CheckBox Control 178
The RadioButton Control 179
The RepeatButton Control 180
The Slider Control 182
The Calendar Control 183
The DatePicker Control 186
The ToolTip Control 187
Items Controls 188
The ListBox Control 189
The DataGrid Control 191
The ScrollViewer Control 193
The ComboBox Control 195
The Popup Control 196
77751ftoc.indd 15 12/18/08 9:58:18 AM
www.it-ebooks.info
xvi
Contents
Media Controls 198
The Image Control 199
The MediaElement Control 200
Displaying Download Progress with the ProgressBar Control 202
The MultiScaleImage Control 203
Silverlight Toolkit Controls 205
AutoCompleteBox Control 206
WrapPanel Control 207
TreeView Control 208
Chart Control 210

Summary 212
Styles and Templates 21Chapter 7: 3
Styles 213
Applying Inline Styles 214
Specifying Styles in a Central Location 218
Templating 224
ControlTemplate 224
TemplateBinding 232
Integrating with ASP.NET 235
Using the ASP.NET Profile Provider 235
ImplicitStyleManager 239
Summary 242
User Interaction 24Chapter 8: 3
The Silverlight Interaction Context 243
Working with UIElements Events 244
Interacting with Input Devices 250
Getting the Most from Input Devices 258
Navigation 266
Silverlight Navigation in the ASP.NET World 266
Single Plug-in Navigation 267
Multiple Plug-in Navigation 280
Summary 283
Communicating with the Server 28Chapter 9: 5
Silverlight Networking and Communication Features 285
What Type of Data Can Silverlight Access and Process? 286
Supported Domains and URLs 286
77751ftoc.indd 16 12/18/08 9:58:18 AM
www.it-ebooks.info
xvii
Contents

Communication Options 286
Data-Processing Options 288
Cross-Domain Support 289
Flash Cross-Domain Policy Files 290
Silverlight Cross-Domain Policy Files 291
Creating Services for Silverlight 292
Creating a WCF Service for Silverlight 292
Creating an ASP.NET Web Service for Silverlight 301
Calling Services with Silverlight 304
Calling a WCF Service 304
Calling an ASP.NET Web Service 308
Calling REST APIs 310
Making RESTful Calls in Silverlight 310
Processing XML Data 314
Processing JSON Data 328
Working with Syndication Feeds 332
Using Sockets to Communicate over TCP 337
Using WCF Polling Duplex Services to Communicate over HTTP 347
Summary 359
Working with Data 36Chapter 10: 1
Data Framework 362
Exploring the Namespaces 363
Is That All? 364
Data-Binding Essentials 365
Binding 101 366
Binding in Practice 370
Conversions 382
Dependency Properties 384
Performance Considerations 386
Retrieving and Storing Data 387

Working with Data Repositories 387
Caching 401
Data Controls 401
Data Templates 402
DataGrid 403
Manipulating Data 407
Traditional Handling 407
LINQ 408
LINQ to XML 412
Validation 416
77751ftoc.indd 17 12/18/08 9:58:18 AM
www.it-ebooks.info
xviii
Contents
Input Validation 416
Using Dynamic Languages 418
Data-Binding Validation 419
Summary 420
Creating Custom Controls 42Chapter 11: 3
User Controls 423
Understanding User Controls 424
Creating User Controls 429
Customizing Current Controls 435
Understanding Visual Customization 435
Customizing with Styles 437
Customizing with Skins 440
Putting Everything Together 443
Custom Controls 447
What Is a Custom Control? 448
Your First Custom Control 449

Parts Model 454
Summary 460
Securing Your Silverlight Application 46Chapter 12: 1
You’re under Attack! 461
The Security Model 463
Working in a Sandbox 466
Cross-Domain Security 470
Integrating with ASP.NET Security 470
Obfuscation 478
Cryptography 479
Summary 479
Audio and Video 48Chapter 13: 1
First Steps 481
Embedding Audio and Video in Your ASP.NET Application 482
Finer Control 491
Controlling Playback 491
Controlling Playback from ASP.NET 500
Timeline Markers 503
SetSource 512
Streaming 514
Summary 514
77751ftoc.indd 18 12/18/08 9:58:18 AM
www.it-ebooks.info
xix
Contents
Graphics and Animation 51Chapter 14: 5
Breathing Life into ASP.NET 515
Before Silverlight 516
Silverlight-Enabled Graphics and Animation 516
Graphics in Silverlight 516

The Shape Class 517
Path and Geometry Objects 521
Painting with Brush Objects 526
Transforms 535
Image Handling 540
Image and BitmapImage 540
Advanced Panning and Zooming with Deep Zoom 542
Animating Your User Interface 547
Timeline 547
From/To/By Animations 547
Key Frame Animations 553
Summary 556
Troubleshooting 55Chapter 15: 9
Is There a Problem? 560
Common Types of Problems 560
Your Toolkit 562
Visual Studio 563
Debugging Your Application 566
HTTP Tracers 570
Red Gate’s Reflector 575
Reducing the Likelihood of Problems 576
Unit Testing 576
UI Testing 581
Exception Handling 586
Instrumentation 587
Summary 587
Performance 58Chapter 16: 9
Performance Bottlenecks 590
Developers versus Designers 590
High Processor Usage 591

Low Frame Rate 591
Unresponsive UI 591
77751ftoc.indd 19 12/18/08 9:58:19 AM
www.it-ebooks.info
xx
Contents
Instrumentation 591
Monitoring the Frame Rate 592
Manual Timing 594
Improving Performance 596
Animation 597
Text 597
Game Loops 598
Windowless 600
Transparent Backgrounds 601
Opacity and Visibility 602
Full-Screen Mode 603
Height and Width 605
XAML versus Images 606
Threading 607
JavaScript versus Managed Code 607
Element Reuse 611
Layouts 612
Working with Data 613
Reduce Chatty Applications 616
Runtime Performance 617
Summary 619
Index 621
77751ftoc.indd 20 12/18/08 9:58:19 AM
www.it-ebooks.info

Introduction
If you’re reading this, then you’re about to start programming rich, immersive ASP.NET applications
with Silverlight, and you want to make sure you get it right first time. Just buying this book gives you
an enormous head start, significantly reducing the learning curve associated with Silverlight 2 develop-
ment, and saving you and your company both time and money. You’re off to the right start.
Our overarching goal in writing this book was to give ASP.NET developers the power to quickly and
easily create visually stunning Internet applications, coupled with rich interactivity to fully immerse
the user in a new online experience. Silverlight gives you everything you need to do just this, and in
serious style!
For the first time ever, the power of the .NET Framework has been unleashed in a plug-in that can be
embedded in multiple browsers across multiple operating systems, giving developers tremendous capa-
bility and flexibility in rich Internet applications development.
As well as taking you through each feature that ships with Silverlight, this book will make sure you’re
able to debug, troubleshoot, and performance-tune your Silverlight applications, as well as seamlessly
hook into your existing ASP.NET architecture and code base.
It’s fair to say that Silverlight is going to change the way that Internet applications are developed and
perceived, and this book will help ensure that both you and your applications keep up!
Who This Book Is For
This book is aimed at .NET developers and architects who want to quickly get up to speed with all that
Silverlight 2 has to offer.
As well as covering the breadth of features that Silverlight 2 provides, this book makes a point of dem-
onstrating where necessary how the particular feature can be integrated tightly with the ASP.NET host
application. An example is in Chapter 7, where the ASP.NET Profile service is utilized directly from
within Silverlight to obtain user-specific data.
It’s fair to say that although this book is aimed at ASP.NET developers, it covers all of the salient fea-
tures of Silverlight 2 to the degree that it’s a useful programming resource for developers not using
ASP.NET also.
If you’re fresh to .NET development, however, you might want to check out a beginning .NET book first,
to help you overcome the syntax and set-up queries when learning a new language. Otherwise, take a
deep breath and dive in!

77751flast.indd 21 12/18/08 9:57:52 AM
www.it-ebooks.info
Intr od uction
xxii
What This Book Covers
This book covers the full feature set of Silverlight 2, diving into each of the subject areas to give depth
and breadth coverage. As well as teaching you about the component parts of the Silverlight API, the book
also covers debugging, troubleshooting, and performance-tuning your Silverlight applications, arming
you with all the skills and knowledge you’ll need to create advanced Silverlight-based applications in
record time.
Importantly, this book covers the integration points between ASP.NET and Silverlight, taking you through
the different techniques you can use to seamlessly augment your existing or new ASP.NET web sites
with the power of Silverlight.
If you want to program in Silverlight and potentially use ASP.NET as the host, then this book covers it all.
How This Book Is Structured
The book is split into two distinct parts. Part I is titled “Silverlight Fundamentals for ASP.NET Developers,”
and Part II is titled “Developing ASP.NET Applications with Silverlight.” Part I is intended to give you
grounding in what Silverlight is as a technology and how it fits into the Web-based landscape. The compo-
nent pieces of a Silverlight application are also laid out at a high level, and any knowledge required before
putting an application together is explained.
Part II is written to give you depth of knowledge across the Silverlight feature-set and show you how to
leverage the power of both Silverlight and ASP.NET to create compelling applications.
A brief synopsis of each chapter now follows:
Part I: “Silverlight Fundamentals for ASP.NET Developers”
Chapter 1: “Silverlight in a Nutshell” — This chapter will teach you at a high level
what Silverlight is and how it can help you deliver engaging, immersive web applica-
tions. Differentiating Silverlight from other Web-based technologies is also covered here,
and a description of the required development environment is provided. In short, after
reading this chapter, you’ll be able to describe Silverlight and explain why you’d want
to use it and what gives it the edge over the competition.

Chapter 2: “Silverlight Architecture” — Silverlight allows you to rapidly build a well-
rounded application with a great user interface, but if you encounter any problems
during development, it is going to be important for you to understand the underlying
architecture upon which you are developing. This chapter outlines the core features of
Silverlight 2 and guides you around the building blocks of this highly flexible frame-
work, paying particular attention throughout to your ASP.NET heritage.
Chapter 3: “XAML Condensed” — Quickly getting up to speed with XAML is what
this chapter is all about, helping you brush aside the syntax queries and get to grips
with the basics of this multi-purpose declarative language. Hooking the XAML files up
to .NET code is also shown here, helping you inject dynamic event-driven actions into
your Silverlight UI. Finally, one technique for the dynamic creation of XAML is shown
in this chapter, followed by a tour of Expression Blend.
77751flast.indd 22 12/18/08 9:57:52 AM
www.it-ebooks.info
Intr od uction
xxiii
Chapter 4: “Programming Silverlight” — By the time you get to this chapter, you’ll
be itching to start coding, and code you will as the feature-agnostic programming con-
structs that make up a Silverlight application are covered in detail. The composition of
a Silverlight application is laid bare and its constituent parts explained at length, as well
as detailing the Silverlight application lifetime and how to hook into it. The different
options for embedding the Silverlight plug-in within your application are covered, fol-
lowed by a brief overview of JavaScript and its associated DOM. This then leads onto a
discussion of the Silverlight Object Model, explaining how the visual tree is constructed
to form the UI. Another technique for dynamically creating XAML and adding it to the
visual tree is also shown here. Finally, the Silverlight event model, browser interaction,
and threading model are covered for you.
Part II: “Developing ASP.NET Applications with Silverlight”
Chapter 5: “Creating the User Interface” — You now know how to program Silverlight
and how to write XAML. This chapter shows you how to put it all together to start

laying out the user interface of your Silverlight application. Each of the layout con-
trols that ship with Silverlight is covered here —
Canvas, Grid, StackPanel, and
TabControl — including information on when to use which one. Information on
how to create a scalable UI is also provided in this chapter, followed finally by a sec-
tion that details how to localize your application, thereby making it available to other
languages and cultures.
Chapter 6: “Silverlight Controls” — Silverlight 2 provides an assortment of controls
that can be used to display and capture data. In this chapter, you’ll learn to work with
user input controls, items controls, and media controls and see how they can be put to
use to build interactive and rich user interfaces. You’ll also learn how to use controls such
as the
MultiScaleImage control to work with Silverlight’s Deep Zoom technology.
Chapter 7: “Styles and Templates” — Altering the look and feel of your application is
the crux of this chapter, with the different techniques for applying styling information
to the controls that comprise it demonstrated here. As well as this, integrating with the
ASP.NET Profile service via WCF is detailed, giving you the ability to personalize your
Silverlight application on a per-user basis.
Chapter 8: “User Interaction” — What’s the point of having a great technology like
Silverlight 2 if we can’t interact with it? In this chapter, we are going to review the
different ways that you can interact with your application, understanding how the
UIElements work with input devices like the keyboard, mouse, and stylus. We also
explore the different ways to navigate around the application and present the differ-
ent options that we have and in which scenarios each one is preferred.
Chapter 9: “Communicating with the Server” — The ability to access data located at
distributed sources is key in many Silverlight 2 applications. In this chapter, you’ll learn
different networking technologies that are available and see how they can be put to use.
Several different topics are covered such as creating and calling ASMX and WCF ser-
vices, calling REST APIs, working with JavaScript Object Notation (JSON) data, push-
ing data from a server to a client with sockets, and leveraging HTTP Polling Duplex

functionality.
Chapter 10: “Working with Data” — It is all about data! One of my colleagues always
says, “If you are not using data binding in Silverlight 2, you are doing something wrong!”
This chapter explains the data framework available within your applications and then
77751flast.indd 23 12/18/08 9:57:52 AM
www.it-ebooks.info
Intr od uction
xxiv
dives deep into the inner workings of data binding, showing you the different approaches
that you may take. In order to understand how the data is retrieved, we explain the dif-
ferent technologies and techniques to get the most of Silverlight 2 data using the avail-
able data controls. Finally, the chapter explains how you can manipulate the data using
LINQ and LINQ to XML.
Chapter 11: “Creating Custom Controls” — This chapter will take you on a journey
in order to discover the different options that you have available to customize the
Silverlight 2 controls. We start exploring the user control model that ASP.NET develop-
ers are used to, and then we dig into the internals of visual customization. You will be
amazed by this powerful new model. Finally, for those who need to push the technol-
ogy to the limit, the chapter explains how to create a complete custom control from
scratch. This is a very dynamic chapter that will present the typical scenarios where
these options may be applied.
Chapter 12: “Securing Your Silverlight Application” — Whether you’re an Enterprise
developer or a Silverlight hobbyist, you are going to want to release your application
out to the wild at some point. In doing so, you are providing a high level of exposure to
your application, and therefore security should not be an afterthought. Thankfully,
Silverlight 2 has a security framework built into the run time, which will give you the
peace of mind of working within a secure environment. This chapter introduces you to
the Silverlight security framework, but also talks you through your security responsi-
bilities as a Silverlight developer.
Chapter 13: “Audio and Video” — Embedding high-fidelity audio and video in your

Silverlight application is sure to capture your users’ imaginations, and this chapter shows
you how you can do just this using the Silverlight-provided
MediaElement control and
the ASP.NET Media Server Control. Playback control is demonstrated, as is the more
advanced topic of providing synchronization points within your chosen media. This
chapter will definitely help you put the WOW factor into your web sites.
Chapter 14: “Graphics and Animation” — A detailed tour of the graphics API that
ships with Silverlight is first discussed here, including the
Shape-derived objects that
can be rendered to screen and also the
Geometry-derived objects that can be created
and then rendered via a
Path object. Brush objects are covered next, demonstrating the
SolidColorBrush, LinearGradientBrush, RadialGradientBrush, ImageBrush,
and
VideoBrush, and their usage. Next up is the very cool DeepZoom technology, cov-
ering the creation of DeepZoom-enabled images using the DeepZoom Composer and
their usage in your Silverlight application via the
MultiScaleImage control. Finally,
the different animation techniques that you can use within your Silverlight application
are covered, ranging from the basic From/To/By type to the more advanced Key frame
types, including the different transition mechanisms within.
Chapter 15: “Troubleshooting” — Writing an application from start to finish without
any development issues is still quite some way off. This chapter introduces you to a
range of techniques and tools to help you through the hard times when your applica-
tion isn’t behaving as you would expect it to. Besides retrospectively fixing problems
within your application, this chapter concludes with the more proactive approach of
ensuring that your application hits a known quality bar before you are satisfied that it
is ready to be released. Silverlight’s testing framework is the flavor of the day here.
77751flast.indd 24 12/18/08 9:57:52 AM

www.it-ebooks.info

×