Books & ebooks about Microsoft tools, technologies, & research. Plus programming best practices. We hope you enjoy this post.
Hello! We’re pleased to announce that the third edition of Laurence Moroney’s Microsoft Silverlight book is now available: Introducing Microsoft Silverlight 3 (Microsoft Press, 2009; ISBN: 9780735625730; 384 pages). (The book shipped to the printer in late May.)
In line with the speedy development of Silverlight, the book follows Laurence’s Introducing Microsoft Silverlight 1.0 in 2007 and Introducing Microsoft Silverlight 2, Second Edition in 2008. The book is based on the Silverlight 3 beta, and when the product is final Laurence will provide updates for the book at his blog.
In this post we’ll share the book’s Content at a Glance, its Introduction, and a stretch of sample text from Chapter 4, “Silverlight XAML Basics.”
The full Table of Contents for Laurence’s book is available here:
http://cid-5a051e94bda12163.skydrive.live.com/self.aspx/.Public/9780735625730%7C_TOC.pdf.
OK, first the Contents at Glance:
And here’s the book’s Introduction:
Introduction
Why Microsoft Silverlight?
As the Web grows and evolves, so do the expectations of the Web user. When the firstWeb browser was developed, it was created to provide a relatively simple way to allowhyperlinking between documents. Then these early browsers were coupled with thecross-machine protocols encompassing the Internet, and suddenly documents stored oncomputer servers anywhere in the world could be hyperlinked to each other.
Over time, the people who were using the Internet changed—the user base expandedfrom a small group of people associated with universities and computational research toencompass the general population. And what had been an acceptable user interface forexperts in the field was greatly lacking for commercial applications. People now wanthigh-quality user interfaces that are simple to use—and as more types of information,including many kinds of media files, are available on the Internet, it becomes more difficultto satisfy users’ expectations about how easy it should be to access the informationthey want.
The need to supply users with sophisticated methods of accessing Internet resources thatwere easy to use led to advanced application technologies. One type of technology, forexample, created “plug-in” browser tools that allowed the browser to use some of theuser’s local computational horsepower.
ActiveX controls, Java Applets, and Flash applications are examples of plug-intechnology. Asynchronous JavaScript and XML (AJAX) is another tool that has beenintroduced to develop new and exciting user interfaces that benefit from immediatepartial updates. Using AJAX, the browser’s screen area doesn’t flash or lock up since theneed for full-page refreshes is reduced.
Although AJAX provides technology to enable developers to build Web sites thatcontain more complex content and are more dynamic than HTML alone could provide,AJAX does have its limitations. For example, it allows asynchronous communication withthe server, which means that applications can update themselves using backgroundthreads, eliminating the screen flicker so often seen with complex Web user interfaces.But AJAX is strictly a browser-to-server communications mechanism. It lacks graphics,animation, video, and other capabilities that are necessary to provide for trulymultimedia user interfaces.
Microsoft has built a Web user experience (UX) strategy to address these limitations byidentifying three levels of desired user experience—“good,” “great,” and “ultimate,”which are mapped to development and run-time technologies. These are combined inthis book with a term you may find that I use a lot—“rich” or “richness.” When I say“rich,” I’m trying to describe a concept that’s hard to put into words. It’s the feeling youget when you use a traditional Web application, with the limitations built into thebrowser and HTML, versus a desktop application that has the entire operating system tocall on for services and capability. The Web applications of today just don’t have thesame feeling and capability as desktop applications, and the user generally realizes thatthey are limited by the technology. With Silverlight (and AJAX), the goal is to create Webapplications that are much more like desktop applications, and ultimately, to createapplications that are indistinguishable from desktop applications.
The lowest level of user experience, the “good” level, can be achieved with the browserenhanced by AJAX. This level identifies the baseline UX expectation moving forwardfrom today—the type of asynchronous, dynamic, browser application empowered byAJAX.
The top or “ultimate” level is the rich client desktop running Windows Vista and usingthe Windows Presentation Foundation (WPF) and the .NET Framework. These offer a runtime that allows developers to create extremely rich applications that are easily deployedand maintained. Broadcast quality graphics, video, and animation are available at thislevel, as well as application services such as file-based persistence and integration withother desktop applications. In addition, WPF separates design and development technologiesso that user interfaces are designed and expressed in a new language calledXML Application Markup Language (XAML). Design tools such as the MicrosoftExpression series were aimed at designers who are now able to produce their work asXAML documents. Developers then use the resulting XAML to bring the designers’dreams to reality more easily by activating the XAML with code.
I mentioned that there are three levels in the UX strategy because as AJAX and.NET/WPF evolved, it became obvious that there was room in the middle for a new technologythat effectively combines the best of both worlds—the global scalability of theInternet application coupled with the richness of the desktop application. This level wasnamed the “great” experience and represents the browser enhanced by AJAX with a newtechnology: Silverlight.
Silverlight is a plug-in for the browser that renders XAML and exposes a programminginterface. Thus, it allows designers and developers to collaborate when building Internetapplications that provide the richness of desktop applications.
The first release of Silverlight exposed a JavaScript-oriented programming model thatprovided powerful scripting of XAML elements within the browser. Silverlight 2 added tothis greatly by including a .NET runtime that allows you to use .NET programming languagesto go beyond this, manipulating XAML, providing a control base, networkingsupport, powerful data libraries, extensibility and greatly improved performance.
Now with the release of Silverlight 3, your tools have gotten broader and more powerful.
In this book, you’ll be looking at Silverlight and how to use it to enhance Web userexperience. You’ll take a broad look at the platform, and how to build applications, mediaexperiences, rich imaging and more.
Silverlight 3 can and will change the way you think about building applications for theWeb. Instead of Web sites, you will build Web experiences. At the heart of a greatexperience is great design, and with Silverlight, designers and developers can cometogether like never before through XAML and the Microsoft Expression line of tools.
In this book, my goal is to help you understand the technologies that work together todevelop and deploy Silverlight Web applications, from writing basic code that usesSilverlight to using advanced tools to create and deliver Silverlight content. When youhave finished reading this book and have worked the examples, you should be ready touse what you’ve learned to enhance the Web applications you’re developing right now.Imagine what you’ll be able to do tomorrow!
Who This Book Is For
This book is written for developers who are already working every day to bring new andbetter Web applications to Internet users and who are interested in adding this cutting edgeMicrosoft technology to their store of knowledge—to find out how it can be appliedas a tool to bring users more interesting, more capable, and more effective userinterfaces. Development managers may also find the easy-to-read style useful for understandinghow Silverlight fits into the bigger Microsoft Web technology picture. Withluck, this book will provide managers with the technological background they need sothat when their developers come to them to talk about Silverlight—with excited looks ontheir faces—they will understand what the excitement is about!
What This Book Is About
This book is broken into two parts. Part I, “Introducing Silverlight 3,” takes you through thebasics of Silverlight. It looks at what Silverlight is and what tools are used to create andmaintain Silverlight experiences, including Microsoft Expression Blend and MicrosoftVisual Studio.
Part I also looks into the XAML technology and how it uses XML to define your entireuser experience, from layout to controls to animation and more. Finally, this part delvesinto the Silverlight plug-in itself and how it can be used to interface with the browser sothat your applications become first-class browser citizens.
Part II, “Programming Silverlight 3 with .NET,” takes you into some more detail on thehigh-level concepts of Silverlight. It’s not an exhaustive reference by any means, but it isdesigned as a straightforward, no-nonsense introduction to the major things that you’llbe doing as a Silverlight developer. You’ll take a two-chapter tour of the built-in controlsbefore looking at how easy it is to build your own controls. You’ll then look at data,communications, programming for animation as well as some of the advanced controlsfor managing media, ink, and the new DeepZoom and Photosynth components that provideeye-popping presentation of images. The book wraps up with a look at the excitingnew Dynamic Languages support in Silverlight.
System Requirements
To develop Silverlight applications as used in this book, you will need the following,available at http://silverlight.net/GetStarted:
For Microsoft Silverlight, the recommended system configuration is 128 MB of RAM and450 MHz or faster processor on Windows and 1 GB of RAM on Intel 1.83 GHz or fasterprocessor on Mac OSX.
For Microsoft Visual Studio 2008, the recommended configuration is 2.2 GHz or higherCPU, 1024 MB or more RAM, 1280 x 1024 display, 7200 RPM or higher hard disk. (Theminimum requirements are 1.6 GHz CPU, 384 MB RAM, 1024 x 768 display, 5400 RPMhard disk.) For Windows Vista, the following is recommended: 2.4 GHz CPU, 768 MBRAM.
Finally, here’s the stretch of sample text from Chapter 4:
XAML Visual Properties
Beyond brushes and location settings, XAML provides a number of other properties to helpyou to control the appearance of your object. By using these properties, you can set anobject’s dimensions, opacity, cursor behavior, and stroke.
Using XAML Dimension and Position Properties
XAML dimensions are set using the Height and Width properties, each of which takes a doublevalue. To create a rectangle that is 100 pixels wide and 200 pixels high, for example, youwould define the XAML as follows:
<Rectangle Fill="Black" Width="100" Height="200" />
In addition, keep in mind that the Top and Left properties attached to the parent canvas areused to specify the relative position of the object.
Consider the following XAML:
<Canvas> <Canvas Canvas.Top="40" Canvas.Left="40"> <Rectangle Canvas.Top="40" Fill="Black" Width="100" Height="200" /> </Canvas></Canvas>
Assume the outmost Canvas is the root canvas for the page. The Rectangle will be drawn 80pixels down from the top of the page as a result. Its parent canvas is 40 pixels down, and theRectangle is 40 pixels down from its parent, for a total of 80 pixels.
Using Opacity
You can set the opacity of an object in two ways. The first is to use the alpha channel in thebrush that is used to fill the object. The following XAML creates a black rectangle on top of animage:
<Image Source="smily.jpg" /><Rectangle Fill="#FF000000" Width="100" Height="200" />
The Fill is set to black (because the red, green, and blue channels are all set to zero), and thealpha is set to opaque (filled with #FF). You can make the rectangle semitransparent bychanging the alpha channel value:
<Image Source="smily.jpg" /><Rectangle Fill="#77000000" Width="100" Height="200" />
You’ll see that the rectangle now appears gray, and the image is visible underneath it.
The second method is to use the Opacity property, which takes a value from 0 (totallytransparent) through 1 (totally opaque). This property is used in conjunction with the alphachannel in the brush. If you use the brush color #77000000 to fill the shape, for example, andthen set Opacity to 1, the rectangle will still be somewhat opaque. If you set it to 0, therectangle will be totally transparent.
Using the Opacity property is useful when it comes to animating the opacity of an object. Itmakes it easy to fade an object in or out using a DoubleAnimation. You can learn more aboutanimation in Chapter 5, “XAML Transformation and Animation.”
Cursor Behavior
With most XAML elements, you can use the Cursor property to specify how the mouse will appearwhen it hovers over an item. This property is set to a value from the MouseCursor enumeration.
Here are a number of the most commonly used enumerations:
Controlling Stroke
The Stroke property determines how a shape’s outline is painted on the screen. This isdifferent from how the object is filled with a brush. In a rectangle, for example, the strokedetermines how the outline of the rectangle is drawn.
Set the Stroke by using a brush. Following is an example of XAML that renders a rectangleusing a simple stroke to specify a black outline:
<Rectangle Stroke="Black" Canvas.Left="40" Canvas.Top="40" Width="100" Height="200" />
In this case, the Stroke property is in fact using a Black SolidColorBrush. It is syntacticallyequivalent to the following XAML:
<Rectangle Canvas.Left="40" Canvas.Top="40" Width="100" Height="200"> <Rectangle.Stroke> <SolidColorBrush Color="Black" /> </Rectangle.Stroke></Rectangle>
By using this syntax (defining the brush as an attached Stroke property), you can specifydifferent types of brushes to draw the shape’s stroke. Following is an example of using aLinearGradientBrush to paint the rectangle’s stroke:
<Rectangle StrokeThickness="10" Canvas.Left="40" Canvas.Top="40" Width="100" Height="200"> <Rectangle.Stroke> <LinearGradientBrush > <GradientStop Color="#FF000000" Offset="0"/> <GradientStop Color="#FFFFFFFF" Offset="0.5"/> <GradientStop Color="#FF000000" Offset="1"/> </LinearGradientBrush> </Rectangle.Stroke></Rectangle>
You can see how this appears on the screen in Figure 4-16.
Setting Stroke Width
You might have noticed in this example that the thickness of the stroke was set to 10. Thiswas done to better demonstrate the gradient, which doesn’t show up well using the defaultstroke thickness value of 1.
Set the stroke width using the StrokeThickness property. This specifies the stroke width inpixels:
<Rectangle StrokeThickness="10" Stroke="Black" Canvas.Left="40" Canvas.Top="40" Width="100"Height="200" />
Setting Stroke Dash
The StrokeDashArray property is used to set the stroke dash pattern. You can combine thisproperty with the StrokeDashCap and StrokeDashOffset properties to fine-tune stroke dash.
To set the stroke of the rectangle to be dashed with a repeating pattern of dashes, you definean array of double values that represents the length of the dashes as well as the spacebetween them. To define a dash pattern using a dash 4 units long, followed by a space 1 unitlong, followed by a dash 2 units long, followed by a space 1 unit long before repeating, youwould set the StrokeDashArray property to (4,1,2,1). Here’s an example:
<Rectangle StrokeThickness="10" Stroke="Black" Canvas.Left="40" Canvas.Top="40" Width="100"Height="200" StrokeDashArray="4,1,2,1"/>
Figure 4-17 shows how this is drawn on the screen.
You can see that these dashes are rectangular in shape, with squared dash edges. You canchange this using the StrokeDashCap property. This property is set to a value from thePenlineCap enumeration. It can contain the following values:
Following is an example of using the StrokeDashCap to set a rounded dash cap:
<Rectangle StrokeThickness="10" Stroke="Black" Canvas.Left="40" Canvas.Top="40" Width="100"Height="200" StrokeDashArray="4,1,2,1" StrokeDashCap="Round"/>
Figure 4-18 shows how this will appear on the screen.
Be nice if the companion website with the source wasn't hosed. Nice job eejits.
Steve, not sure what page you're referring to. This is the page with the companion content, and it's working: http://www.microsoft.com/learning/en/us/Book.aspx?ID=12578&locale=en-us#tab2