Channels ▼
RSS

.NET

What's New in Silverlight 2?


Dan Wahlin is a .NET development instructor and architecture consultant at Interface Technical Training. Dan founded the XML for ASP.NET Developers Web site, which focuses on using ASP.NET, XML, AJAX, and Web Services in Microsoft's .NET platform. Dan blogs at http://weblogs.asp.net/dwahlin and http://blogs.interfacett.com/dan-wahlins-blog.


Rich Internet Applications (RIAs) provide a way to build dynamic user interfaces that simplify the process of accessing and displaying data to end users. Microsoft's Silverlight 2 product adds many new features that let .NET developers more easily build RIAs without facing the large learning curve normally associated with new technologies. The learning curve is still there, of course, but by leveraging your existing VB.NET or C# skills you can minimize the slope and begin building applications more quickly.

In this article I introduce new features available in Silverlight 2 and discuss why they're important. Many advancements have been made since the release of Silverlight 1 that are key especially if your applications target a variety of browsers and end users. In future articles, I will drill-down into new features and provide additional details on how they can be used to build RIAs using Silverlight 2.

Do I Still Have to Use JavaScript?

One of the most important advancements available in Silverlight 2 is the inclusion of a mini Common Language Runtime (CLR) that can run on multiple operating systems including Windows and Macintosh (with Linux support coming through the Moonlight project. Version 2 lets you write VB.NET or C# code that will run in Internet Explorer, FireFox, and Safari which means you don't have to use JavaScript any longer as with Silverlight 1. As a result, you can leverage your existing programming skills to build Silverlight 2 applications without having to learn a new language or object model. Several of the namespaces and classes available in the full version of the .NET Framework are also available to use in Silverlight 2.

Listing One presents an example of handling a Button control's Click event using C#. Looking through the code, you'll see that it looks a lot like standard ASP.NET event handler code aside from the RoutedEventArgs parameter that is passed.

private void btnSearch_Click(object sender, RoutedEventArgs e)
{
   HtmlPage.Window.Alert("Button Clicked!");
}
Listing One: Handling events in Silverlight 2.

Where are the Controls?

Silverlight 1 provides a solid framework for building RIAs using XML Application Markup Language (XAML) and JavaScript. Using XAML elements available in version 1 along with some JavaScript code you can animate objects in creative ways, skew and resize objects and interact with data dynamically using AJAX technologies and Web Services. However, many developers coming from an ASP.NET or Windows Forms background wondered (aloud at times) where all of the controls were for capturing user input and displaying collections of items. Aside from the TextBlock control, the MediaElement control and shape controls such as Rectangle and Ellipse, no user input or data display controls were available in version 1 and laying out data on a page wasn't as straightforward as it should be. I've heard more than more developer ask, "Where are the controls?"

The good news is that Silverlight 2 provides more than 25 controls that can be used to layout other controls as well as capture and display data. All of the controls can be defined in XAML or created dynamically through VB.NET or C# code. Each control exposes properties, methods and events typically found in ASP.NET and Windows Forms controls, and can even be customized through styles (see www.corrina_b.members.winisp.net/skins/rough/Testpage.html for an example). Figure 1 shows what the Silverlight 2 project Toolbox looks like in Visual Studio 2008.

Figure 1: Silverlight 2 controls available in the Visual Studio 2008 Toolbox.

Silverlight 2 controls can generally be classified into several categories including layout controls, user input controls, media controls, shape controls, and a few miscellaneous controls.

Let's take quick look at new layout, user input, and media controls.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video