Getting Started with Silverlight 2
Some people say Microsoft's Silverlight technology is a "Flash
killer," but I'm not sure that I agree. The similarities are striking.
Both Adobe Flash (formerly Macromedia Flash) and Silverlight are
browser plug-ins. Both support vector graphics, audio and video playback,
animations, and scripting support. But their underlying technologies are
different; Flash uses a semi-open binary format, and Silverlight is based on
WPF. Before it was called Silverlight, the technology was
code-named WPF/E (Windows
Presentation Foundation Everywhere). And thanks to good browser support,
Silverlight does really run everywhere, at least in theory.
At the time of this writing, Silverlight plug-ins are available for
the two big players, Microsoft Internet Explorer and Mozilla Firefox on Windows.
Also, a Mac OS X plug-in exists that targets Safari and Mozilla Firefox on the Apple platform. According
to Microsoft, other platforms were considered, but given the high market
shares of Windows and Mac OS X, these
browsers were given priority.
Silverlight 2 requires Windows 2004 SP4 or higher (i.e., Windows XP,
Vista, Server 2008) to run. Opera support is planned for a future release; Opera is currently
the third most used browser and has a relatively small but very loyal user
The Mono project (http://www.mono-project.com/), renowned for its open source
implementation of .NET, is working on an open source Silverlight port that
targets the Linux platform (and the Firefox browser there). This
project is called Moonlight (see http://www.mono-project.com/Moonlight for a sneak peek).
shows some up-to-date screenshots of those efforts (see Figure 1). Microsoft has also announced that it is teaming
with Novell to support the Moonlight project and bring
Silverlight to Linux.
Figure 1. Some Moonlight screenshots
But what exactly is Silverlight, apart from a browser plug-in
provider? The heart of the plug-in is the graphics subsystem, which supports
a certain subset of WPF . It also
includes the codes responsible for displaying audio and video content .
1. Setting Up a Silverlight Development System
For the programming part of Silverlight, a text editor would
suffice, actually, but it is by far more productive for you to use a
"real" development environment. The most obvious choice is to use some of
Microsoft's offerings. From a code perspective, Visual Studio 2008 is currently the best choice for
developing Silverlight 2 content. The full versions (Standard Edition,
Professional Edition, and Team Suite) and the free Visual Web Developer
Express Edition work. If you can use a paid version, you will get project
template support, so that's preferable. We will use Visual Studio 2008
Standard Edition throughout this book. Whenever there are differences to
the free Express Edition, this will be especially noted so that those
users don't miss out on any important information.
There are no special prerequisites for installing Visual Studio or
Visual Web Developer apart from using Windows XP or higher. You do not
even need a web server, as the IDE comes with one! However, if you can,
you may want to install Microsoft's IIS (Internet Information Services).
IIS is hidden in the control panel, under Software (Vista: Programs), where you can turn Windows
features on and off (see Figure 2).
When installing Visual Studio 2008, make sure you select
the Visual Web Developer option (see Figure 3). Otherwise, the web editor will not be part of
your IDE, which you need to create web sites since Silverlight is a web
technology, whereas WPF is a desktop technology. If you want to use Visual
Studio 2008 Express Edition, you can download a web-based installer at
Figure 2. Installing IIS
Figure 3. Make sure you install Visual Web Developer as part of Visual
Whatever version of Visual Studio you install, you should apply any available service packs right away.
(As of this writing, no service pack has been released, but you never
know.) For Visual Studio 2005, Windows Vista users had to install a
special Vista update patch as well. This is not necessary any longer for
Visual Studio 2008, but it gives you a good idea why it is important to
check for patches often.
The most convenient way to get your system up-to-date regarding
software patches for Microsoft products is to use the built-in Windows
Update mechanism. Microsoft Update is an extended version of that service.
Windows Update gives you patches only for Windows and core Windows
components such as Internet Explorer, but Microsoft Update also
patches other Microsoft products, including Office, Visual Studio,
and SQL Server (see Figure 4).
Activating Microsoft Update depends on which Windows edition you are
using. For versions prior to Windows Vista, just go to the update web
site, which will install the feature (http://update.microsoft.com/microsoftupdate/). If you are
using Windows Vista, launch Windows Update from the Start menu and then
choose the "Get updates for more products" link (see Figure 5). The next time you search for updates, you will
also get patches for Visual Studio (and other installed Microsoft
Figure 4. Switch to Microsoft Update to get more than just Windows
Figure 5. Microsoft Update offers you more updates, including those for
Visual Studio (here: Version 2005)
Once the IDE is up and running, it is time to make it
Silverlight-aware. For both Silverlight 1.0 and 2, Microsoft provides
SDKs. We are using the version 2 SDK in this book (see Figure 6). The final version of the Silverlight SDK is
available in the Microsoft Silverlight download section at http://msdn2.microsoft.com/en-us/silverlight/bb187452.aspx.
It installs documentation, Silverlight libraries including controls,
additional ASP.NET server controls for Silverlight, and tools to enable
CLR debugging. The SDK also offers to install a Visual Studio 2008
template. Afterward, you can install the Visual Studio 2008 Tools for
Silverlight from http://www.microsoft.com/downloads/details.aspx?FamilyID=25144c27-6514-4ad4-8bcb-e2e051416e03&DisplayLang=en.
This includes additional tools for Visual Studio's Silverlight support
(see Figure 7). Visual Studio then gets several new
templates, including a C# web site project template section for
Silverlight (see Figure 8). Starting with a template
such as this really facilitates all subsequent steps, since a web site
based on these templates comes with a lot of helper code so that you don't
have to type it all. At the time of this writing, Microsoft was preparing
an all-in-one installer that installs the SDK, the Visual Studio add-in,
and a browser plug-in (see Figure 9).
You need Visual Studio 2008 to install the templates; Visual Web
Developer cannot use them.
Figure 6. The Visual Studio Tools for Silverlight installer
Figure 7. The Silverlight SDK installer
Figure 8. The new Silverlight templates in Visual Studio
Figure 9. The Silverlight Tools installer
Now you are ready to create Silverlight content, at least in a code