Table of Contents

Cover

Title Page

Copyright

Dedication

About the Author

About the Authors

Credits

Acknowledgments

Introduction

Who This Book Is For

What This Book Covers

How This Book Is Structured

What You Need to Use This Book

Conventions

Source Code

Errata

p2p.wrox.com

Part I: Getting Started

Chapter 1: Introduction to Silverlight

What Is Silverlight?

Silverlight Versions Explained

Application Development Scenarios

Getting the Silverlight Plug-In

Getting the Silverlight SDK

Building Silverlight Applications

Silverlight 3 Tour

Summary

Chapter 2: XAML Basics

Introducing XAML

Silverlight XAML Basics

Declaring Objects in XAML

XAML Hierarchy

Events and the Silverlight Control

Markup Extensions

Summary

Chapter 3: Silverlight Architectural Tour

Browser Host

Presentation Core

.NET

Summary

Chapter 4: Silverlight Developer Toolbox

Silverlight 3 Tools

Developing with Silverlight 3 Tools for Visual Studio 2008 SP1

Designing with Expression Blend 3

Generating Video Using Expression Encoder

Summary

Part II: Using Silverlight 3 Essentials

Chapter 5: Controls

Text Input

DataGrid

ListBox, ComboBox, and TabControl

Button, HyperLinkButton, and ToggleButton

GridSplitter

Silverlight Controls Toolkit

Summary

Chapter 6: Silverlight Text

Text Support in Silverlight

Displaying Text with TextBlock

Summary

Chapter 7: Layout

Measure, Then Arrange

Element Sizing Characteristics

Layout Panels

Custom Panels

Silverlight Plug-In Sizing and Position

Summary

Chapter 8: Styling Your App and Dealing with Resources

Getting Started

Local Styling (Inline Styling)

Styling with Resources

Working with the Style Object

Defining and Organizing Resources

Summary

Chapter 9: Using Graphics and Visuals

The Basics

Images and Media

Brushes

Fonts and Font Embedding

Effects and Perspective 3D

Importing Artwork from Additional Design Tools

Summary

Chapter 10: Making It Richer with Media

Supported Formats

Unsupported Windows Media Formats

H.264 and AAC Support

Using the MediaElement Control

Media Playlists

Summary

Chapter 11: Using the Services

Communications

Storage

Installation and Updates

Summary

Part III: Building Applications

Chapter 12: Silverlight, the Browser, and the Server

Silverlight All by Its Lonesome

Silverlight with the Browser

Silverlight with the Server

Summary

Chapter 13: First Things First: Handling Cross-Cutting Concerns

Security

Exception Handling and Logging

Summary

Chapter 14: Dealing with Data

Getting Data to Your Application

Binding a User Interface to Data

Persisting Data in Isolated Storage

Summary

Chapter 15: Designing and Styling the User Interface

The Players

Gathering Requirements

UI Brainstorming/UX Sessions

Design/Dev Part Ways

Integration Phase

Continuous Iteration

Final Polish/Cleanup

Summary

Chapter 16: Making the Application Come Alive

Events

Responding to User Activity

Personalization

Internationalization

Dates and Times

Summary

Chapter 17: Creating Custom Controls

Setting Up a Control Project

Using a Custom Control in an Application

The Parts Control Model

Taking Advantage of Visual States

Including Dependency Properties

Building a Content Control

Summary

Appendices

Appendix A: Silverlight Base Class Libraries Reference

Appendix B: System.Windows Reference

System.Windows Classes

DependencyObject Class

UIElement Class

FrameworkElement Class

Appendix C: System.Windows.Media Reference

System.Windows.Media

Appendix D: System.Windows.Shapes Reference

System.Windows.Shapes Classes

Appendix E: Additional Resources

Index

Advertisement

Silverlight™ 3 Programmer’s Reference

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-38540-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 permission 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 http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties 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 Web site 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 Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared 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 trademark 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.

Non nobis, Domine, non nobis, sed nomini Tuo da gloriam. — Ambrose Little

I dedicate this book to my beautiful wife, Sheri, and amazing daughter, Siena, who put up with my crazy schedule and who forgive me every time I need to do things like write a book chapter or two when I really should be having fun with them. — Jason Beres

To Ania, my wife and best friend, for supporting me through the long hours and late nights. — Grant Hinkson

For Kyle — Devin Rader

To Laura, my loving wife, and my two children, Joey and Annabelle, whose beaming smiles and endless support give me the inspiration and strength to tackle big challenges. — Joseph Croney

About the Authors

Ambrose Little lives in central New Jersey and works there for Infragistics, where he is working mainly on new product development. As an INETA speaker and Microsoft MVP, he’s been known to show up occasionally at user groups and write the occasional article and book. He’s been designing and developing real business applications for more than 10 years.

Jason Beres is the director of product management for Infragistics, the world’s leading publisher of presentation layer tools. Jason is also one of the founders of Florida .NET User Groups, the founder of the New Jersey .NET User Group, a Visual Basic .NET MVP, on the INETA Speakers Bureau, and on the INETA board of directors. Jason is the author of several books on .NET development, an international speaker, and a frequent columnist for several .NET publications. He also keeps very active in the .NET community.

Grant Hinkson is director of the experience design group at Infragistics. He is passionate about design, usability, and technology and is rewarded by working with a team of people who share similar passions. Grant is a Microsoft Expression MVP, a contributing author of Silverlight 1.0, published by Wrox, and Foundation Fireworks CS4, published by Friends of Ed, and a contributing author on Adobe DevNet. He has spoken at Adobe MAX, Microsoft ReMIX, and DevScovery and is active in the WPF, Silverlight, and Fireworks communities. He has authored several utilities for the designer/developer community, including the Fireworks to XAML exporter. When not coding or designing, Grant enjoys playing both the piano and the organ.

Devin Rader is a product manager on the Infragistics Web Client team, responsible for leading the creation of Infragistics Silverlight and Data Visualization products. Devin is also an active proponent and member of the .NET developer community, being a cofounder of the St. Louis .NET User Group, an active member of the New Jersey .NET User Group, a former board member of the International .NET Association (INETA), and a regular speaker at user groups. He is also a contributing author on the Wrox titles Professional ASP.NET 2.0, Professional ASP.NET 3.5, and Wrox Silverlight 1.0, as well as a technical editor for many other Wrox publications. He has also written columns for ASP.NET Pro magazine and .NET technology articles for MSDN Online. You can find more of Devin’s ramblings at www.geekswithblogs.com/devin.

Joseph Croney is director of product development at Infragistics, where he leads a worldwide team of engineers that delivers cutting-edge software components for Silverlight, WPF, and ASP.NET. He is a former Microsoft program manager, who led feature teams in the MSN, Mobility, and Developer divisions. After leaving Microsoft, Joseph founded Calabash Technologies, a U.S. Virgin Islands Technology start-up, which successfully built and introduced a revolutionary handheld GPS Tour Guide. While CEO of Calabash, Joseph found time to share his passion for Computer Science with the next generation of technology leaders as an advanced-placement computer science teacher. Joseph has spoken at a wide range of events, including Microsoft PDC, ASP.NET Connections, Microsoft TechEd, and the College Board’s National Convention.

Credits

Executive Editor Bob Elliott

Senior Development Editor Tom Dinse

Technical Editors Jess Chadwick, Ed Blankenship, Todd Snyder, Ben Hoelting, Steven Murawski

Senior Production Editor Debra Banninger

Copy Editors Cate Caffrey, Foxxe Editorial Services

Editorial Manager Mary Beth Wakefield

Production Manager Tim Tate

Vice President and Executive Group Publisher Richard Swadley

Vice President and Executive Publisher Barry Pruett

Project Coordinator, Cover Lynsey Stanford

Associate Publisher Jim Minatel

Compositor Craig Johnson, Happenstance Type-O-Rama

Proofreader Nancy Carrasco

Indexer J & J Indexing

Acknowledgments

Thanks first to my wife, Christiane, and four munchkins — Bridget, John, Brendan, and Thomas — for letting me disappear down into the basement for so many hours to work on this book, being patient, understanding, and supportive. Thanks to my coauthors for their hard work despite our ridiculously busy schedules; to Tom, Debra, and Bob at Wrox for sponsoring and coordinating; and to all our editors, technical and otherwise, who helped make this book better. It has been a tremendous team effort.

— Ambrose Little

I would like to take this opportunity to thank the Wrox team, especially Tom Dinse, who kept this book on track and made sure we all did what we needed to do to keep our tight schedule. I would also like to shout out a very special thanks to the great author team — Devin, Ambrose, Joe, and Grant — for making this book happen. It was awesome doing this book and even more awesome working with you guys at Infragistics every day.

— Jason Beres

First, thanks to my wife, Ania, for your constant support and encouragement on yet another after-hours project. Thanks also to my family for constantly encouraging and supporting me along the way. Finally, thanks to my coauthors and fellow XDGer’s at Infragistics — it’s a pleasure working with you all!

— Grant Hinkson

I thank my wife, Kathleen, for putting up with the late nights and working weekends. Once again, I say this is the last one. Thanks also to my Mom and Dad for all of your support and advice.

Thanks to my coauthors who put so much time and effort into the book, who were a bit wiser this time and yet still signed on. Thanks to all of those at Wiley, especially Bob Elliott and Jim Minatel, for giving us the opportunity to do this book and for keeping us moving in the right direction through its creation.

— Devin Rader

I would like to take a moment to recognize all the people who contributed to making this book a success. First and foremost, I want to thank my coauthors and the staff at Wrox, who spent countless hours dedicating their time and talent to the project. I also want to recognize my Silverlight development team, especially Stephen Zaharuk, whose technical expertise and support proved invaluable while I was exploring the depths of Silverlight. Finally, I thank my family for making the personal sacrifices that allowed me the time to focus on making this book a reality.

— Joseph Croney

Introduction

To abuse an already abused cliché, we are at a tipping point for the Web and application development in general. The last several years have seen a notable shift away from basic full-page-based, postback-intensive web applications that minimized the use of JavaScript in favor of server-side code for maximum browser compatibility. Today, some amount of AJAX is assumed for any new web application, and every day we see new “Web 2.0” applications and companies popping up.

At the same time, and in part because of this shift, the old “thin client” versus “rich client” dichotomy has increasingly faded. It is entirely possible, and, indeed, it is often the case, for a Web-based application using AJAX to truly have a richer experience than most desktop-based applications, be they Windows Forms, Java, or MFC. In fact, one might say that web applications today set the bar (excluding games, of course).

Enter Windows Presentation Foundation (WPF), the long-awaited, updated Microsoft desktop-application user interface (UI) framework. WPF borrowed from what has been learned on the Web (such as markup-based interface declaration and good separation of UI concerns), unified multiple Windows graphics APIs, and introduced new capabilities to Windows-based applications and new platform features (such as the enriched dependency property system, commanding, triggers, declarative animations, and more). WPF re-established the desktop as the new “rich client,” although not without contest from fairly rich Internet applications (RIAs) that were based on AJAX.

But this book is not about AJAX. Nor is it about WPF, at least not directly. It’s about bringing together these two worlds of RIAs and rich WPF-based desktop applications, and that’s where Silverlight comes in.

Silverlight was originally codenamed WPF/e, meaning “WPF everywhere.” And that’s a pretty good tagline for Silverlight — bringing the good stuff from WPF to all the major platforms today, including OS X and flavors of Linux (via the Linux “Moonlight” implementation).

Silverlight 1.0 was an initial salvo. It brought with it the rich media, the rich UI declarative model, and a subset of WPF’s presentation layer capabilities. But it still depends on JavaScript for the development environment and browsers’ JavaScript execution engines. It does not have many of the basic application development facilities that developers today have come to expect and rely on, such as a control model (and controls), data binding facilities, and a solid development environment with reliable IntelliSense and debugging. Building a truly rich application for Silverlight 1.0 was only marginally better than using AJAX — the key advantages were in the high-quality media player and, of course, animation facilities.

The fall of 2008 brought Silverlight 2 and now, just a few months later, we’re seeing a respectable update with Silverlight 3. Silverlight 3 and up will inevitably become the de facto Microsoft RIA development platform, and not just for Internet but also (in this author’s opinion) for line-of-business solutions, except in cases where the functional or experiential demands call for the greater power of WPF. That said, although dramatically improved over Silverlight 1.0 and light-years better than building on AJAX frameworks, in many ways, even Silverlight 3 is still something of a fledgling RIA platform. But hey, that’s more because RIAs and the necessary infrastructure to support them are still relatively young.

Silverlight 3, in a broad sense, brings pretty much all the goodness of the .NET development platform to the browser. Almost everything you need from the .NET Frameworks that would apply in a browser environment is at your disposal. Oh, and did I mention, that includes a CLR especially crafted for RIAs?

So, why say that it is a fledgling RIA platform? Well, apart from the fact that what was essentially the real 1.0 version of what Silverlight needs to be as a RIA platform (Silverlight 2) was just released last fall, RIAs in themselves introduce a not-exactly-new but new-to-many-developers application model. You are essentially forced into a three-tier model that many, perhaps most, Microsoft developers have only given lip service to. You can no longer simply write ADO.NET code to directly access a database — you must go through a network service, be that HTTP or TCP-based, and for many developers, this will no doubt be a stumbling block. However, for those who have been developing true three-tier applications, while it may not be a stumbling block, they will appreciate the added complexity that this model imposes. Silverlight 3 does little to alleviate this burden, although when .NET RIA Services come to fruition, they will go a long way toward ameliorating this extra complexity.

On the flip side (architecturally speaking), there are no doubt client-side facilities that can and will mature. Silverlight 2 added isolated storage, which is essentially a sandboxed local filesystem, and that’s a great start. But there are architectural facilities — such as those provided by Enterprise Library (e.g., enhanced exception handling and reporting, tracing, logging, caching) and those such as identity authentication and authorization — that need to be developed for this application model and platform.

Certainly there will also be new facilities whose need emerges as more and more RIAs are built as well with a focus on simplifying UI development itself. The raw power is there today, but it will require skill sets that historically have been relegated to high-end software development. (We’re speaking here of various kinds of designers, particularly visual designers and interaction designers.) Because, as they say, with great power comes great responsibility, end-users have and will continue to expect more and better user experiences that the RIA platforms can provide.

Yet, despite how far there is to go to mature Silverlight into the rich application platform it needs to be, Silverlight 3 is, as noted, light-years ahead of developing RIAs on AJAX. In some ways, Silverlight does not add much in the way of experiential capability over a rich AJAX framework (or a combination of them). A lot of the basic and not-so-basic animations and, of course, asynchronous capabilities can be had without Silverlight, and certainly it is easier today to build rich AJAX-based applications than in even very recent years past.

But it is still terribly difficult not only to build but also to maintain a truly rich Internet application on AJAX. Although we developers might enjoy the immense technological challenge; the exciting intellectual stimulation of dancing between CSS, HTML, XML, and JavaScript; the sheer joy of screaming at the monitor when the beautiful set of functionality you finally got working in Firefox totally falls apart in Internet Explorer; the exhilaration of dealing with angry customers who have somehow disabled (or had disabled by corporate policy) one of the several technical puzzle pieces your application relies on — we, in the end, could be putting our collective intelligence and valuable time into far more valuable and rewarding — for everybody — enterprises.

And this is one of the chief areas where Silverlight 3 rushes to the rescue. By giving you a reliable CLR; .NET Frameworks; the WPF-based presentation core (including controls, data binding, and much more); a better networking stack; local, isolated storage; a rich IDE with rich debugging, IntelliSense, and LINQ (and even a Dynamic Language Runtime, DLR); Silverlight makes developing rich interactive applications far more feasible for everybody, especially our patrons (businesses), who are concerned with the total cost of ownership, not just what’s technically feasible. And for developers, except for those few die-hard JavaScripters, Silverlight will undoubtedly be a source of newfound joy in productivity and empowerment.

Why Write This Book?

So that’s all fine and dandy. Silverlight is just awesome. But why bother writing a book about it?

The reason is simple. Silverlight 2 was the first and biggest step toward fundamentally changing the future of web (and, indeed, all) application development, and Silverlight 3 carries that forward. It is one of the first pure Internet (cloud, if you will) development platforms. It is the culmination of years of technological evolution toward a new future where computing will truly be ubiquitous. It will be a key enabler in this new world of better user experiences with ubiquitous computing devices.

It is obviously just one piece of that puzzle, but it is a crucial one. The world is moving away from the desktop, and therefore we can’t be restricted to it for rich software experiences. We want to help developers make this crucial step toward that future.

Will learning Silverlight make you magically able to develop these great experiences? No. There are other skills to learn and certainly other professionals who will need to take part in making that future. But Silverlight (and platforms like it) is the future of software, and if you don’t want to get left behind, this is about as good a place to go next as you can pick.

This book will help you take that step. We propose to cover most, if not all, of this new platform as it stands in its current incarnation. While doubtless, given the rapid nature of change, some of this book will soon become obsolete, nearly all of it will be applicable as the Silverlight platform matures.

You may not need to use Silverlight today, but you will soon. What this book provides both by way of tutorial and reference will be an invaluable guide from seasoned developers and designers. It will help you see past the fluff and the marketing hype to the real challenges and problems that you as a programmer will face in developing applications on the Silverlight platform.

So what are you waiting for? Don’t become the next COBOL dinosaur — dive into this book and make yourself relevant now and for years to come!

Who This Book Is For

This book embodies the Wrox philosophy of programmer to programmer. We are experienced programmers writing for other programmers. We wrote the book with the average business application developer in mind. Certainly, others can derive value — anyone trying to build on or even just understand the architectural concerns and realities of Silverlight — but this is at its heart a true programmer’s reference.

What This Book Covers

While other books on Silverlight may spend inordinate amounts of time on the finer points of shapes, brushes, and styling — the fancy UI glitz that WPF and Silverlight do, indeed, bring to the table — we recognize that most application developers need a more holistic understanding of this new platform and what it offers and does not offer for building real, especially business-oriented, applications. We do cover the UI glitz (which is really great), but at a fundamental level that most devs need; what we strive to do is put that in perspective and offer not only the technical details, but also a sort of wisdom that we hope will help you better build on this platform.

This book, obviously, focuses in on Silverlight 3 (Build 40522), but we cover related technologies and concerns that developers will need to know about when building on Silverlight 3, and, as noted previously, most of what is covered here will remain relevant even as the platform matures.

How This Book Is Structured

This book is broken into four main parts. The first part is an introduction and provides an overview of Silverlight 3 and how to get started with it. It’s safe to say that if you read nothing else, you’d probably want to read this part, but the other parts are where this book’s value really shines.

Part 2 covers the essentials of what Silverlight 3 gives developers in the box. Its focus is on the presentation core of Silverlight, which is more or less the “new” stuff in Silverlight that most .NET developers will have to learn in terms of new APIs, objects, services, and concepts.

Part 3 builds on the basics from the first parts but does not necessarily presume that you have read it. The purpose of this third part is to walk through the various concerns that an application developer would have in building a real application on Silverlight. This is the real meat of the book. While we do reference relevant parts of an application called Lumos throughout, we do not assume that you have read prior chapters in most parts. The book is more like a generic front-to-back application tutorial, so if you only need to read up on or reference how certain application-building concerns (e.g., data binding) can be addressed in Silverlight, you can safely dive into that particular chapter or section with minimal difficulty. The chapters are ordered more or less in terms of how you should think about building applications, starting with architectural, cross-cutting concerns and moving through the other concerns in a manner that would make sense to a developer building a real application on this platform.

Part 4 contains reference Appendixes. These are for your use when you need to consult a specific API. We try to add value here over the MSDN library reference, and certainly we focus in on Silverlight-specific APIs.

The high-level approach we suggest is to read Parts 1 and 2 once through. This will give you a good foundation to start playing around in Silverlight. Part 3 is especially valuable as a holistic application building reference — you can jump to sections you are currently dealing with in the applications you are building; however, it can (and perhaps should) be read straight through to give you a more holistic understanding of what it takes to build solid applications in Silverlight. Part 4 is not intended to be read through; we recommend just using it as needed, but it may offer insights and details that the other parts only touch on, so you shouldn’t ignore it!

What You Need to Use This Book

You need your hands and eyes to use this book unless, of course, you have the highly secret audio version! Seriously, we try to list all relevant code along with supplemental text to explain it, so you don’t need to lug a computer with you to get value from reading this. We even have color for most of the book to make the code listings that much easier to read and to give you a better sense of what the underlying code results in when run. (This is a rich UI technology, after all!)

But if you do have your computer handy, you can download the samples (or recreate them) using the tools outlined in Chapter 4. In short, there’s nothing required that you shouldn’t be able to download freely from the Internet.

Conventions

To help you get the most from the text and keep track of what’s happening, we’ve used several conventions throughout the book.

Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:

We highlight new terms and important words when we introduce them.

We show keyboard strokes like this: [Ctrl]+A.

We show URLs and code within the text like so: persistence.properties.

We present code in two different ways:

We use a monofont type with no highlighting for most code examples.

We use highlighting to emphasize code that's particularly important in the 

present context.

Also, Visual Studio’s code editor provides a rich color scheme to indicate various parts of code syntax. That’s a great tool to help you learn language features in the editor and to help prevent mistakes as you code. To reinforce Visual Studio’s colors, the code listings in this book are colorized using colors similar to what you would see on screen in Visual Studio working with the book’s code. In order to optimize print clarity, some colors have a slightly different hue in print from what you see on screen. But all of the colors for the code in this book should be close enough to the default Visual Studio colors to give you an accurate representation of the colors.

Source Code

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com. Once at the site, simply locate the book’s title (either by using the Search box or by using one of the title lists), and click on the Download Code link on the book’s detail page to obtain all the source code for the book. \

Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is 978-0-470-38540-1.

Once you download the code, just decompress it with your favorite compression tool. Alternatively, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

Errata

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata, you may save another reader hours of frustration, and at the same time, you will be helping us provide even higher quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the Book Details page, click on the Book Errata link. On this page, you can view all errata that have been submitted for this book and posted by Wrox editors. A complete book list including links to each book’s errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml, and complete the form there to send us the error you have found. We’ll check the information and, if appropriate, post a message to the book’s Errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com, you will find several different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

1. Go to p2p.wrox.com and click on the Register link.

2. Read the terms of use and click Agree.

3. Complete the required information to join as well as any optional information you wish to provide, and click Submit.

4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

You can read messages in the forums without joining P2P, but in order to post your own messages, you must join.

Once you join, you can post new messages and respond to messages that other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum emailed to you, click on the “Subscribe to This Forum” icon by the forum name in the forum listing.

For more information about how to use the Wrox 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.

Part I: Getting Started

Chapter 1: Introduction to Silverlight

Chapter 2: XAML Basics

Chapter 3: Silverlight Architectural Tour

Chapter 4: Silverlight Developer Toolbox

Chapter 1

Introduction to Silverlight

Silverlight 3, the third iteration of the Silverlight platform, continues to deliver on the promise of Adobe Flash–like and Flex-like rich Internet applications (RIAs) built using a standards-based, open approach with HTML and XAML using tools like Visual Studio 2008 and Microsoft Expression Blend. Silverlight 3 adds more excitement to RIA development with the inclusion of a subset of the Base Class Libraries (BCLs) from the .NET Framework, new user interface controls, and new libraries for building line-of-business applications. The result is that not only do you have the rich, XAML markup to describe expressive user interfaces, but you also have the power of the .NET Framework and your language of choice (C#, VB, etc.) to build Silverlight applications. Even with the .NET Framework libraries, Silverlight still retains the cross-browser and cross-platform compatibility that it has had since the beginning. This includes Windows 2000, Windows XP, Windows Vista, Windows 7, Macintosh, and, through the Mono Project, various Linux distributions. You can build a Silverlight application and run it in a Safari Web browser on an Apple Macintosh, while being served up from an Apache Web Server running on Linux. There is a lot to learn about Silverlight, and you’ll gain more and more insight with each chapter in this book.

This chapter does two basic things:

It gives you an introduction to Silverlight.

It sets the groundwork, with the essentials on creating Silverlight applications, that will help you move on to the next chapter and the rest of the book.

What Is Silverlight?

Silverlight is a Web-based platform for building and running RIAs. The Web-based platform part of that equation is essentially the plug-in that runs inside the Web browser. Silverlight applications execute within an ActiveX browser plug-in that installs onto the local machine via the Web browser in the exact same manner that you install Adobe Flash to run Flash-based animations on Web pages. The Silverlight plug-in supports the entire wow factor that you’d expect from an RIA, such as vector-based graphics and animations and full video integration, including Digital Rights Management (DRM) secured audio/video and hi-definition video, as well as the tools for building rich line-of-business applications. You can boil down the coolness of Silverlight to the following points:

Silverlight is a cross-platform, cross-browser platform for delivering rich interactive applications.

Silverlight 3 applications can be built using Expression Blend, Visual Studio, or Eclipse on Windows, and with Eclipse on Apple Macintosh computers.

Silverlight supports playback of native Windows Media VC-1/WMA (with Digital Rights Management) as well as MPEG-4-based H-264 and AAC audio on PCs and Macs with no dependency on Windows Media Player.

Silverlight supports playback of 720p+ full-screen HD Video.

Using XAML, HTML, JavaScript, C#, VB (or your managed language of choice, including dynamic languages like Ruby and Python), Silverlight delivers rich multimedia, vector graphics, animations, and interactivity beyond what AJAX can deliver.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!