Introduction xxi Part I: Silverlight Fundamentals for ASP.NET Developers 1 Chapter 1: Silverlight in a Nutshell 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 Chapter 2: Silverlight Architecture 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 COPYRIGHTED MATERIAL
Chapter 3: XAML Condensed 31 xiv 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 Chapter 4: Programming Silverlight 63 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
Part II: Developing ASP.NET Applications with Silverlight 119 Chapter 5: Creating the User Interface 121 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 Chapter 6: Silverlight Controls 167 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 xv
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 Chapter 7: Styles and Templates 213 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 Chapter 8: User Interaction 243 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 Chapter 9: Communicating with the Server 285 Silverlight Networking and Communication Features 285 What Type of Data Can Silverlight Access and Process? 286 Supported Domains and URLs 286 xvi
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 Chapter 10: Working with Data 361 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 xvii
Input Validation 416 Using Dynamic Languages 418 Data-Binding Validation 419 Summary 420 Chapter 11: Creating Custom Controls 423 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 Chapter 12: Securing Your Silverlight Application 461 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 Chapter 13: Audio and Video 481 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 xviii
Chapter 14: Graphics and Animation 515 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 Chapter 15: Troubleshooting 559 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 Chapter 16: Performance 589 Performance Bottlenecks 590 Developers versus Designers 590 High Processor Usage 591 Low Frame Rate 591 Unresponsive UI 591 xix
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 xx