CoverStory
LANGUAGES: XAML | JavaScript | C#
ASP.NET VERSIONS: 3.5
Head Toward the Light
Getting Started with Silverlight 1.0
By Dan Wahlin
The overall acceptance of AJAX and Flash technologies in Web applications has led to the creation of more and more rich applications that provide an enhanced next generation user experience. End users are accustomed to visiting Web sites that show advertisements and media clips with Flash and load dynamic content with AJAX. With the release of Silverlight 1.0, Microsoft has thrown their hat into the rich Web experience ring and provided a nice foundation for developers to build upon. Silverlight works on Windows and Mac operating systems, and in multiple browsers, including Internet Explorer, FireFox, and Safari.
If you ve heard about Silverlight, but haven t yet had a chance to experiment with it, it s a browser plug-in that can play audio and video, perform animations and transformations, and enhance the way data is displayed in a Web page. You can download the plug-in and associated software development kit (SDK) and view many eye-catching Silverlight demos at http://silverlight.net.
Silverlight 1.0 is all about a declarative language named XML Application Markup Language (XAML), as well as JavaScript. It can also leverage various AJAX frameworks, including ASP.NET AJAX, to obtain data dynamically. Many demos focus on how audio and video can be added to Silverlight applications because it s very good at these types of tasks. But Silverlight can be used in many other scenarios, from games to data display. In this article, I ll provide an introduction to various features available in Silverlight 1.0, and describe the different pieces needed to make Silverlight work. Let s get started by looking at the overall architecture of Silverlight 1.0.
Putting the Pieces Together
Silverlight has several key technology players that are needed to make things work in a Web page. First, XAML is used to define the content displayed by Silverlight. XAML is an XML-based mark-up language that also is used by Windows Presentation Foundation (WPF). The version of XAML available in Silverlight 1.0 contains a sub-set of the overall XAML specification, as the Silverlight plug-in needs to stay small to allow for quick downloads and installations. Using XAML, you can define shapes, such as rectangles and ellipses, embed .wmv and .wma media files, perform snazzy animations to move objects around, and transform objects to perform interesting effects. I ll provide an introduction to XAML in the next section of the article.
In addition to XAML, Silverlight 1.0 relies on JavaScript to create a Silverlight control instance at run time, and to programmatically access various objects and media defined in XAML. In cases where you need to dynamically add content to Silverlight, you can use JavaScript to perform asynchronous operations (AJAX operations) without reloading the entire Web page. Any AJAX framework can be used, from Prototype to ASP.NET AJAX, to retrieve data and inject it into Silverlight.
Figure 1 shows the overall Silverlight architecture as defined in the Silverlight 1.0 SDK. You ll see that it provides support for decoding media, working with events, rendering content and text, parsing XAML, downloading objects used by Silverlight, performing animations, plus more.
Figure 1: The architecture of
Silverlight 1.0.
Now that you ve seen the main Silverlight components, let s see how they work together. The basic steps to use Silverlight in a Web page are shown here:
1) Create a new Web site in Visual Studio or Web Developer Express.
2) Add the Silverlight.js file to the Web site.
3) Create an XAML file that Silverlight will consume.
4) Add a Web page with a
5) Add a custom CreateSilverlight.js file to the site.
6) Call Silverlight.createObject or Silverlight.createObjectEx within CreateSilverlight.js to create a Silverlight instance at run time.
7) Reference the Silverlight.js and CreateSilverlight.js files in the Web page using the