The overall goal of this book is to inform and educate you about the exciting and powerful Silverlight 4 platform. Think of it as a guided tour through the Silverlight 4 plug-in, runtime libraries, and SDK. After you’ve read this book, you should be able to confidently design, develop, and deliver your first rich interactive applications using Silverlight. To facilitate the learning process, I’ve structured the book to get you developing as soon as possible, while providing quality, in-depth content.
Within each chapter, I’ve included a collection of devices to help you build a firm understanding of Silverlight. The following list explains how each agent helps along the journey:
In addition to these learning devices, my personal site http://10rem.net contains links to the code samples used in this book. Additionally, http://silverlightinaction. com, the web site for the first edition, includes assets, images, and services used in this book.
This book is intended for developers who want to create nontrivial applications using Microsoft Silverlight 4. Though Silverlight provides numerous avenues for interactions with designers, this book primarily targets people who live and breathe inside Visual Studio. Team members in the integration role (those who take designs and implement in Silverlight) will also find the information valuable and useful.
Experience with previous versions of Silverlight isn’t required for this book.
This book provides ample opportunity for hands-on learning. But, it also provides a great deal of flexibility by allowing you to learn the material without using the hands-on content or optional tools. If you want to get the greatest value out of this book and use the hands-on opportunities, the following tools are recommended:
You’ll find links to all of these tools at http://silverlight.net/GetStarted.
This book is designed to give you a guided tour of Silverlight 4. This tour will focus on three main areas: introducing Silverlight, structuring your application, and completing the experience.
Chapter 1 introduces Silverlight. The introduction shows you the advantages of Silverlight and explains its place in the desktop and web applications arenas. The chapter wraps up with a walkthrough of building your first Silverlight application.
Chapter 2 covers one of the most fundamental parts of Silverlight: XAML. Though most of the book covers XAML in one form or another, this chapter takes you from the fundamentals all the way through the visual and logical trees, the dependency property system, and XAML extensions.
Chapter 3 explains how the Silverlight plug-in and application startup process work. You’ll learn about the application object, the .xap file, and caching assemblies. We’ll also look at how to instantiate the plug-in and use it on a web page.
Chapter 4 builds on the browser integration introduced in chapter 3 and shows how to manipulate the HTML DOM from Silverlight, work with the browser window, and bridge the scripting and managed code worlds. This chapter also introduces the Silverlight
WebBrowser control, used to display web content within Silverlight itself when running out of the browser.
Chapter 5 takes us out of the Web and onto the desktop. Silverlight supports creating both sandboxed and elevated trust desktop applications. This chapter covers out-of-browser applications, local file access, COM automation, custom window chrome, working full screen, and using isolated storage.
Chapter 6 covers the layout and rendering system and both 2D and 3D transformations. If you truly want to understand what’s happening when you put pixels on the screen, knowledge of the layout and rendering system is a must. This is information that I personally found deeply interesting; I hope you do as well. This chapter also covers 2D transformations, such as skew and translate, as well as 3D plane and matrix projection.
Chapter 7 builds on the layout information from chapter 6 to show how to use the various types of layout panels in Silverlight including the
Chapter 8 brings us the human connection. Though everything so far has been about presenting, this is about gathering. We’ll learn how to use the keyboard, mouse, ink, and touch interfaces to perform actions in our applications.
Chapter 9 covers text input and output. I start off with a discussion of the text stack, including information on antialiasing strategies and the common text properties of controls and the
TextBlock element. From there, I look at text input controls such as the
RichTextBox, with a side journey into IME and international text.
Chapter 10 introduces several of the nontext controls including the
ListBox, and more. This chapter also covers the base control types common to the stock and custom controls, such as
Chapter 11 covers binding. In Silverlight, if you find yourself assigning values directly to controls in the code-behind, as the meme goes, “you’re doing it wrong.” Binding is one of the most powerful features of Silverlight and is something we’ll build upon in the chapters that follow.
Chapter 12 builds on what we learned in chapter 11 to make use of the
DataForm controls. In this chapter, I also cover the use of data annotations to control display attributes for your entities.
Chapter 13 also builds on chapter 11 and 12 to provide validation capabilities to our applications. I cover exception-based validation, synchronous and asynchronous validation using interfaces, validation using attributes, and creating your own custom validators.
Chapter 14 helps our Silverlight applications break out of the client and communicate with servers on the Internet and intranet. In this chapter, we learn how to use SOAP and REST web services, the underlying web stack, sockets, and even local connections between Silverlight applications.
Chapter 15 is a deep dive into using the Navigation Framework, windows, and dialogs in your application. We’ll look at how to structure your application as a series of pages, handle URL addressing and mapping, and parameter passing. We’ll also learn about the built-in dialogs and the
Chapter 16 covers the MVVM pattern and unit testing. Without picking any one specific MVVM (or ViewModel) framework, I show you the concepts behind the ViewModel pattern and how to implement them in your own application. This chapter wraps up with information on testing Silverlight applications using the Silverlight Unit Testing Framework.
Chapter 17 covers one of the most exciting developments for business and other data-oriented applications: WCF RIA Services. We’ll walk through creating a RIA Services application using the Business Application template and look at everything from query and update operations to business rules and validation to security.
Chapter 18 dives into vector graphics and brushes—key concepts for creating applications that move beyond the usual controls. This chapter also goes into depth on effects and pixel shaders, wrapping up with information on how to build your own custom shader in HLSL and C#.
Chapter 19 covers working with the printer from Silverlight. Silverlight 4 introduced the ability to print short documents or handle print-screen functionality. We go over the API and wrap up this chapter with an implementation of a custom reporting solution for short reports.
Chapter 20 is all about media: video and audio. In this chapter, I go over the various ways to present video and audio in your application, including IIS Smooth Streaming and custom managed code codecs using
MediaStreamSource. I also dive into the webcam and microphone API covering basic use as well as creating your own
VideoSink to manipulate the returned data.
Chapter 21 is to still images as chapter 20 is to video and audio. In this chapter, we look at how to use bitmap images in your application, including approaches for generating images at runtime.
Chapter 22 covers animation and behaviors. You’ll learn how to use storyboards to liven up your interface. After that, we take a look at using and creating behaviors to package up your own reusable functionality, often containing animations.
Chapter 23 covers styles, templates, and resources. We look at how to package up style information for controls and how to create completely new templates using the lookless control model.
Chapter 24 teaches us how to create layout panels and custom controls. Though you can do almost anything in Silverlight with a new control template, there are times when creating your own control or panel is the way to go.
Chapter 25 wraps up the book with information on creating the best possible install experience for the plug-in, as well as the best possible loading experience for your own applications.
All the code used in this book is presented in a
this. This code can be in one of a variety of languages; the language used is indicated at the beginning of the code block. For longer lines of code, a wrapping character may be used to be technically correct while forming to the limitations of a printed page. Annotations accompany many of the code listings and numbered cueballs are used when longer explanations are needed.
The source code for all of the examples in the book is available for download from the publisher’s website at www.manning.com/Silverlight4inAction and from the author’s website at http://10rem.net.
The purchase of Silverlight 4 in Action includes free access to a private forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the author and other users. You can access and subscribe to the forum at www.manning.com/Silverlight4inAction. This page provides information on how to get on the forum once you’re registered, what kind of help is available, and the rules of conduct in the forum.
Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It isn’t a commitment to any specific amount of participation on the part of the author, whose contributions to the book’s forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions, lest his interest stray! The Author Online forum and the archives of previous discussions will be accessible from the publisher’s web site as long as the book is in print.
In addition to the Author Online forum available on Manning’s website, you may also contact us regarding this book, or anything else, through one of the following avenues:
Pete Brown is a Community Program Manager with Microsoft on the developer community team led by Scott Hanselman, as well as a former Microsoft Silverlight MVP, INETA speaker, and RIA Architect for Applied Information Sciences, where he worked for more than 13 years. Pete’s focus at Microsoft is the community around client application development (WPF, Silverlight, Windows Phone, Surface, Windows Forms, C++, Native Windows API, and more).
From his first sprite graphics and custom character sets on the Commodore 64 to 3D modeling and design through to Silverlight, Surface, XNA, and WPF, Pete has always had a deep interest in programming, design, and user experience. His involvement in Silverlight goes back to the Silverlight 1.1 alpha application that he co-wrote and put into production in July 2007. Pete has been programming for fun since 1984 and professionally since 1992.
In his spare time, Pete enjoys programming, blogging, designing and building his own woodworking projects, and raising his two children with his wife in the suburbs of Maryland.
By combining introductions, overviews, and how-to examples, the In Action books are designed to help learning and remembering. According to research in cognitive science, the things people remember are things they discover during self-motivated exploration.
Although no one at Manning is a cognitive scientist, we are convinced that for learning to become permanent it must pass through stages of exploration, play, and, interestingly, retelling of what is being learned. People understand and remember new things, which is to say they master them, only after actively exploring them. Humans learn in action. An essential part of an In Action book is that it’s example driven. It encourages the reader to try things out, to play with new code, and explore new ideas.
There is another, more mundane, reason for the title of this book: our readers are busy. They use books to do a job or solve a problem. They need books that allow them to jump in and jump out easily and learn just what they want just when they want it. They need books that aid them in action. The books in this series are designed for such readers.