User Name:
Published: 14 Oct 2008
By: Faisal Khan
Review of the book Silverlight 2.0 In Action
With the invention of Silverlight, we already stepped into the future of web application. With the release of Silverlight 2, the door has been opened for us to use the power of the .NET Framework to reach beyond the desktop to deliver fascinating experiences across a variety of web browsers, platforms and devices. The implementation of this new technology has been explained wonderfully by Chad Campbell and John Stockton in their book, “Silverlight 2 In Action”, as they teach Silverlight step by step. One of the excellent features of this book is that the chapters have been ordered logically to help developers understand the in-depth concepts behind Silverlight 2. Whether you’re a professional or a novice programmer and want to get your feet wet with the world of RIA (Rich Internet Application), this is exactly the book you want. I’m expressing my personal opinion here about each chapter of this book.
In chapter 1 productivity, performance and portability are discussed nicely. The Designer/Developer role is so important in the world of RIA and that has been described by the writers of this book in an innovative way. How XAML enables a refreshing, collaborative experience between designers and developers that allows us to create valuable software solutions in shorter amounts of time has also been explained in this chapter with some great examples.
One of the highlights of this chapter is an in-depth analysis of XAML and how XAML pages support the concept of code-behind pages to enable us to separate code from design by placing the UI related code in the XAML and the executable code within a linked source file. The authors did a great job of clarifying this concept. You’ll find all the crucial issues such as namespaces, compound properties and attached properties in this chapter.
The first walkthrough demonstrates the seamless integration between the Microsoft Visual Studio and Blend tools. How expression Blend tools can be used to stylize the media has been shown in this walkthrough. After reading this chapter, I have come in contact with the power of XAML and the most important stuff, using Expression Blend and Visual Studio together. This is vital for any integration scenario where design and development needs to be combined to make a good Silverlight application.
In Chapter 2 you’ll gain a deeper understanding of the Silverlight plug-in. You’ll learn the relationship between Silverlight and the HTML DOM and how to manage HTML DOM elements from managed code. For example, how can we place Silverlight anywhere we want within a web property and how DOM allows us to embed a Silverlight plug-in within it, etc. You’ll also find the HTML DOM, Silverlight plug-in and the Silverlight Object Model described in detail here. You’ll gain knowledge about creating the Silverlight control and how this control can be created at least in two different ways.
Many core concepts are discussed in this chapters, including:
The last section of this chapter discusses how Silverlight allows us to create a bridge between the scripting and managed code which includes basic steps intended to expose managed code elements to the scripting world. It describes how we are free to reference the managed elements from JavaScript. After reading this chapter, I’ve strengthened my previous knowledge of HTML DOM concepts. I was a little confused about embedding Silverlight plug-in within the DOM and managing web page from code but this chapter has removed my confusion.
Chapter 3 is all about layout panels and text. The writers have shown here the use of the Canvas element to deliver rich ink content. They’ve shown us how the content within a Canvas is automatically arranged for us. How the attach property can be used to move the content at some other places, has been explained nicely. The use of the StackPanel to represent a grouping of visual elements has been illustrated with some useful examples such as how each successive visual element is positioned in a vertical or horizontal fashion within a single row or column; or how we can use the Orientation property of the StackPanel to specify whether child elements are stacked in a vertical or a horizontal manner, etc.
Canvas
StackPanel
Orientation
The power of the Grid control has been shown with its ability to easily layout content in a tabular format. Use of Silverlight Grids, Rows and Columns two distinct collections, ColumnDefinitions and RowDefinitions are explained quite intelligently. All the features of the Grid have been represented by showing some declarative and procedural examples. Text plays a vital role in Silverlight applications. You’ll see some examples of the TextBlock element to flexibly display text in various situations. The next section of this book covers the UIElement and FramworkElement. This section discusses how a significant amount of flexibility enhances our applications in innovative ways. A number of valuable and interesting methods and properties of UIElement and FrameworkElement have been described here. In this chapter I’ve learnt about the pillars of the Silverlight UI, which are crucial to structure any good Silverlight UI. Another basic concept, which I think is necessary for anyone who wants to grasp a good understanding of UI principles, is the concept of UIElement and FrameworkElement. This chapter does a nice job of simplifying this issue.
Grid
Grids
Rows
Columns
ColumnDefinitions
RowDefinitions
TextBlock
UIElement
FramworkElement
FrameworkElement
FrameworkElement
In Chapter 4, you’ll step into the world of user interaction. You’ll learn in this section how user input is a vital part of virtually every web application and how to collect this input. You’ll become familiar with the issues regarding Silverlight’s direct support for input devices like keyboard, mouse, and stylus through the use of the System.Windows.Input namespace. Here you’ll gain a strong understanding of focus in order to handle your key strokes. Two events directly related to the keyboards are explained in this part nicely.
System.Windows.Input
You’ll learn how to deal with modifier keys. Modifier keys are keys that are used in combination with other keys. These are necessary because the KeyEventArgs class only exposes information about the currently pressed key. Because of this, if you select something like the SHIFT or CTRL key, and then another key, the initially selected key data will be lost. To overcome this problem, you learn how you can take advantage of the statically visible keyboard class that has been described here with a procedural code example. You’ll also learn how to trap the mouse. Mouse related events available in Silverlight are discussed greatly in this section. The mouse is slightly more complex than the keyboard. In addition to button related events, the mouse can also respond to movement. Movements can be measured to enhance experience alongside the keyboard and to take the measurements and deliver a user-friendly drag-and-drop interface, including some very useful tips that you’ll find here.
KeyEventArgs
The next section of this chapter focuses on delivering the text controls. Over the course of this section, you will learn how to handle basic text entry with the TextBox. In addition, you will see how to collect hand written data through the powerful InkPresenter control. You’ll learn how selected text can be programmatically retrieved through three TextBox properties. To gather and display ink with the InkPresenter you’ll learn three important steps, including how to create the InkCanvas and also how to style the ink. In the next part you’ll become familiar with the general implementation of a Button and how it is spread across two classes, ButtonBase and ContentControl. ButtonBase is an abstract base class used by all Buttons in Silverlight. About three members of ButtonBase class which are directly related to user’s interaction etc.
TextBox
InkPresenter
TextBox
InkCanvas
Button
ButtonBase
ContentControl
Buttons
Some important thing about ContentControl and how it is designed to display a single content has been described here. The other sections of this chapter deal with HyperlinkButton, RadioButton, CheckBox, ItemControls, ListBox, TabControl, Date Controls, Calendar, Datepicker which are so important from a Silverlight developer perspective. Silverlight enables you to simulate a dialog box through a control called the Popup. You’ll learn all about Popup in this section. You’ll understand the Popup behavior and positioning the Popup to get your feet wet. Next you’ll learn how to prompt for a file using the OpenFileDialog class. Throughout this section you will learn the three steps involved in interacting with an OpenFileDialog. Next you’ll find two more important elements, Border and Slider. You’ll understand what RangeBase class actually does. This chapter clarifies the main characteristics and purpose of the interaction.
ContentControl
HyperlinkButton
RadioButton
CheckBox
ItemControls
ListBox
TabControl
Calendar
Datepicker
Popup
Popup
OpenFileDialog
OpenFileDialog
Border
Slider
RangeBase
In Chapter 5 you’ll find all the data related issues. Throughout this chapter you will see how to handle data once it is in memory. You’ll see the different sources of data that you can bind to. The data binding mechanism available in Silverlight has been presented here with some good examples. You’ll also learn to convert data when it comes in different formats. From there you will experience how to work with data through a DataGrid. Finally, this chapter ends with an overview of the distinguishing data querying enhancement known as LINQ. I’ve strengthened my knowledge of querying data with LINQ from this chapter.
DataGrid
You’ll get a clearer view of networking and communication in this chapter. How networking and communications enable us to send and receive data with variety of technologies is a major aspect of this chapter. Concepts behind working with technologies like SOAP services, XML, JSON, RSS, ATOM and Sockets are discussed here. You’ll learn the basics of connecting to different services and how to parse data once received. You’ll also find a couple of ways to enable push communications in this chapter. You’ll become aware of the very important concept of cross-domain and the clientaccesspolicy.xml file. This chapter shows why it’s necessary to put a clientaccesspolicy.xml file at the root of the domain hosting any web service that is allowed to be accessed from a different domain. Limitations of the browser connection limits and asynchronous calls have also been discussed. To me this, is one of the most important chapters as far as sending and receiving data is concerned and this really helped me to work with JSON, RSS and ATOM in Silverlight.
In chapter 7 you will learn how to use various items from within the System.Windows.Controls namespace. This chapter shows how to manage media experience through the use of playlists and interactive playback. From there you’ll learn how to access protected content and finally, you’ll see how to incorporate traditional images and utilize the existing DeepZoom features. This chapter shows how Silverlight goes far beyond standard web capabilities by providing a full screen mode. You’ll learn how Silverlight enables you to view two different screen modes, toggling between screen modes, etc. The authors have skillfully presented the issues related to using protected content, requesting protected content, retrieving the PlayReady components, unlocking protected content, using Images, basic imaging, showing an Image with the MultiIScaleImage control to get the DeepZoom experience, deploying MultiScaleImages and still more. to take you to the next crucial round of your Silverlight journey. Anyone who is very interested in DeepZoom will find this chapter extremely helpful.
System.Windows.Controls
DeepZoom
PlayReady
Images
Image
MultiIScaleImage
MultiScaleImages
In chapter 8 you’ll get a grip on Silverlight graphics which plays such an important role in attracting the user’s attention. You’ll learn here that the graphics within Silverlight are mathematically based objects and how this makes them ideal for Internet distribution. Concepts of geometries have been discussed here and after this you’ll learn how to paint your shapes and alter the way in which they are rendered. You’ll become familiar with all of the graphical elements like Shape, Rectangle, Line, Ellipse, Polyline, Polygon etc.
Shape
Rectangle
Line
Ellipse
Polyline
Polygon
To paint these elements, the usage of different Brushes like SolidColorBrush, LinearGradientBrush, RadialGradientBrush, ImageBrush and VideoBrush are covered. The next section of this book shows the uses of the Transform element to alter the appearance of any UI Element within Silverlight. You’ll learn the usage of RotateTransform, ScaleTransform, SkewTransform and TranslateTransform. You will see how to create some of these graphical features using Blend. From there, you will know how to write the code that responds to a user’s actions to interact with a graphical element. I gathered useful knowledge on graphics and their transformations from this chapter.
SolidColorBrush
LinearGradientBrush
RadialGradientBrush
ImageBrush
VideoBrush
RotateTransform
ScaleTransform
SkewTransform
TranslateTransform
Chapter 9 Focuses on Animation. Throughout this chapter you’ll learn how to bring life to the various elements and others objects with the help of Silverlight’s built in animation. You’ll see the practical uses of animation to dramatically improve a user’s experience. How animation in Silverlight changes a single value of property over a period of time has been discussed in this chapter with some great examples. The chapter focuses all the important terms to master this area of Silverlight. Mastering the Timeline, what type of property you’re animating, three types of animations which will assist you in creating the dramatic effects, where are you starting from and where are you going, how long the animation should run, throttling the animation, an in-depth analysis of storyboard, the usage of storyboard as a resource and trigger, key framing, interpolations like Linear Interpolation, Spline Interpolation, Discrete Interpolation and timing are all demonstrated in this chapter.
After completing this chapter you’ll gain the complete understanding of Silverlight animation. This is one of the most amazing chapters of this book. For someone who is interested in stepping into the rich and cool world of animation, this chapter is ideal. This chapter helped me to really comprehend the tips and tricks of animation.
This is a crucial and a fun chapter and you’ll learn very important and enjoyable features of Silverlight. The cornerstone of this chapter is to give your application’s UI a different look and feel to bring richness by using Style, Template and VisualStateManager. You’ll also learn contents that are non executable pieces of data and the image, media file as well as the XAML file fall into one of three categories: declarative resources, loose resources and embedded files.
Style
Template
VisualStateManager
You’ll learn here why a resource is a vital part of a Silverlight application. In the declarative resources section you’ll know what ResourceDictionary actually is and where and how to define it; how to use storyboards, styles and template items as resources, how resources can be defined at design time and run time. In the loose resources section of this chapter, you’ll see how Silverlight provides the ability to access loose resources. Two different ways of accessing local resources have been discussed in a section of this chapter. In the bundling resources section you’ll come to know two types of bundled resources and their uses.
ResourceDictionary
In the next section of this chapter you’ll learn how files can be added as content to a project then built to a xap file structure. You’ll also become aware of the fact that embedded files in Silverlight can also be an application or a library. The next section discusses giving styles to the elements, and how to define their look by setting the Styles property, which is available to every FrameworkElement. The “Creating templates” section will show you how to redefine the entire visual representation of elements to get the desired look. In the “Dealing with visual state” section you’ll learn how to transition from one state of a control to another. In the following section you’ll know how VisualStatesManager relies on variety of components to do its job and why these components are referred to as the parts and states model. This chapter has given me the concepts of logical and visual structure of the control and enough ideas to apply themes to the application by the use of resources in Silverlight.
Styles
VisualStatesManager
Chapter 11 discusses how to enrich the user’s experience using Silverlight’s runtime features, and how these features give us the ability to store and retrieve data on the user’s machine through isolated storage. You’ll see the process of loading XAML, processing data, and downloading files without interrupting the UI. You’ll know here how to access the isolated storage area for a user and use it to manage a virtual file system. Listing the contents of the virtual file system, removing items from Isolated Storage, creating directories with Isolated Storage, checking the available space, requesting more space, how a file within the isolated storage can be created and retrieved through a file stream, administering the isolated storage are all discussed in this chapter.
You’ll also learn how to use XAML at runtime. In the following section of this chapter you’ll learn all about the Background worker. How it can be used for performing a task behind the scenes and how it enables us to asynchronously perform a task on a thread separate from the UI thread. You’ll gain an understanding of how the BackgroundWorker is useful for web service calls, complex calculations and other time-consuming operations.
You’ll get a grip on retrieving content on demand with WebClient class. How this class acts as a special utility class that enables us to asynchronously download the content has been clarified by the authors in this chapter. Requesting string and binary data, managing larger download requests, loading the string content and media, loading fonts, loading compressed packages, loading application modules, how to deal with the termination when On Demand download requests stopped in one of two ways: intentionally or unintentionally. This chapter finishes with one of the most powerful Dynamic Language Runtime issues. How Dynamic Language Runtime (DLR) enables on-the-fly compilation and execution of a variety of scripting languages such as Jscript, IronPython and IronRuby. You’ll know how these languages take advantage of features such as garbage collection, memory management, and type-safety checking. This section discusses the advantages and disadvantages of two interesting characteristics of dynamic languages. I left this chapter with a crystal clear idea of DLR, WebClient and BackgroundWorker.
Chapter 12 has shown the process of creating Silverlight user controls. Some key factors have been presented here. For example, how a user control can be used as a page in Silverlight. After completing this chapter you’ll be able to define the appearance and behavior of the user control. You’ll learn how to enhance CLR properties. You’ll know how to take advantage of the dynamic characteristics of the Dependency property.
This chapter also shows how to include user controls in your application by adding xml namespace that references the location of the user control. Silverlight does not provide an elegant way to switch between XAML files directly out-of-the- box. To use more than one XAML file and switch between them how you have to architect your application and you’ll learn all about those tricks in this chapter. The discussion here uses an imaginary master-detail implementation to demonstrate how this architecture works. You’ll learn how to create a custom splash screen in a scenario where your application is larger in size or when network will run slow. Here you splash screen’s appearance will be fixed and how splash screen is integrated is shown in this section. You’ll also know how to monitor the progress and update the splash screen when download is proceeding.
The last section of this chapter describes Silverlight streaming. Silverlight streaming is a free hosting service which give you several gigabytes of space to rapidly deploy Silverlight content. You’ll learn how this content can be hosted in the form of an audio, video or image file. You’ll get the concept of packaging your Silverlight content to be deployed over Silverlight Streaming. Initially, I was little confused about the Dependency property in Silverlight and streaming, but chapter has removed all the confusion.
This is such a wonderful book that it has thrust me into the realm of innovation. I’m strongly recommending this book to everyone, whether you’re a professional developer or just a beginner and want to learn the basics of Silverlight to experience the tips and tricks of building RIAs (Rich Internet Applications) . After thoroughly reading this book, I have come to the conclusion that this book is enough to turn this world around with Silverlight. Kudos to Chad Campbell and John Stockton for their excellent writing..
David J Kelley
Silverlight MVP