Category Archives: Silverlight

WPF XAML Markup – How Do I Preserve Whitespace Characters?

An issue you’re likely to run into in XAML (WPF, XBAP, and SIlverlight applications) is the need to keep whitespace characters intact in your markup.  By default, XML collapses all whitespace, ignoring strings of spaces, tabs, and return characters inside an XML node, which it graciously converts to a single space.

If you want to include a series of spaces in your XML node markup, you can add a xml:space=”preserve” attrbute to your XML elements.  This attribute  is part of the XML standard.  If you turn it on, it preserves all whitespace appearing inside the XML node, including any hard return characters included inside the XML node.

<Button Name="btnSample" xml:space=preserve">Respects my      spaces
and carraige return</Button> it! digg it! reddit! technorati! yahoo!

XAML Soup – XBAP vs. Silverlight 1.0 vs. Silverlight 2.0

Microsoft offers several new technologies to provide Rich Internet Applications (RIAs) to end users using WPF technology.  Silverlight 2 gets the most press as Microsoft’s “Flash Killer”, but it’s good to understand how these technologies relate, and the differences between them.

  • WPF Browser Applications (XBAPs)
  • Silverlight 1.0 (formerly dubbed WPF/E, Released)
  • Silverlight 2.0 (formerly dubbed Silverlight 1.1, currently in Beta 2)

All 3 technologies allow you to build dynamic user interfaces for the browser using the Windows Presentaion Foundation (WPF) using a browser plug-in.  You can use XAML to build front end UI elements, including some way cool transitions, blends, and animation.  You use code-behind to code against the UI and to add functionality to wire up the controls and respond to events, similar to the way you would in ASP.Net.

The primary difference between the three technologies is:

  • Browser / OS support
  • .Net Framework suppport
  • Language support

XAML Advantages Over Flash

Because these technologies are XAML, the markup is XML content, not binary like Flash.  This is a subtle but MAJOR difference:

  • XAML pages are indexable by search engines today.
  • XAML is accessible via the Document Object Model. This means that the same techniques you use in AJAX to update a particular part of the tree can be used to update a particular portion of a Silverlight application.  Document.GetElementById just got a lot more powerful.
  • Most of the skills you’ve developed in using the .Net Framework and building WPF applications are transferable to Silverlight application development

XBAP vs. Silverlight

.NET 3.0 introduced the Windows Presentation Foundation (WPF) which allows developeres to create stunning user interfaces for desktop applications using managed code. If you still haven’t experienced the power of WPF check out the WPF applications here.

The first step toward bringing WPF to the web was XBAP – XAML Browser Application (XAML is eXtensible Application Markup Language). XBAPs allow you to run Rich Internet Applications that look and function like WPF desktop applications. These XBAPs run inside the Internet Explorer in a limited-trust sandbox to prevent applications from accessing resources on the local system.

A restriction on XBAPs is that they need .NET framework 3.0 or higher to be installed on the client machine to run, and they only run on Windows systems under IE.   If you’re not in a tightly controlled intranet environment where you can dictate IE on Windows with the 3.0 framework on every client, Silverlight is the way to go.

Silverlight 1.0

Silverlight (formerly dubbed WPF/E) extends the boundaries by removing the dependency on the .Net framework, and providing cross-platform, cross-browser support to WPF applications with a browser plug-in.  As of now, Silverlight supports a subset of XAML and .Net functionality.

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.

Although Silverlight 1.0 is powerful, it is a 1.0 release, and it has some serious shortcomings. 

  • Very limited control set.  Aside from a few very basic controls (Canvas, TextBlock, MediaElement, and basic shape controls) no user input or data display controls were included in version 1.  Control layout was also much too difficult. 
  • No support for the .Net framework, C# or Visual Basic.  Code behinds mucst be coded in Javascript, which is a web developer skillset, which may not overlap with WPF developers and doesn’t integrate natively with the Visual Studio development and debugging experience. 
  • Limited support for browsers and operating systems.  It’s currently supported with plug-ins for IE and FireFox on Windows.  Additional plug-in’s for  popular browsers on Linux and Mac platforms are currently in the works from 3rd party vendors.

Make Way For Silverlight 2.0

Silverlight 2.0 recently RTM’d, and moves the framework ahead nicely, with major improvements over the 2.0 release, including:

  • Adds a pared-down version of the .Net Framework complete with a miniature CLR hosted by a browser plug-in
  • Provides many new controls that can be used to capture user input and display collections of items
  • Ability to write C# or VB.NET code that runs in the Internet Explorer, Firefox, and Safari browsers
  • Includes networking features that allow data from local and remote services to be integrated into applications

Getting Started

To get started, you should install Visual Studio 2008 and Silverlight Tools for Visual Studio.  For more information, see the Getting Started page on the Silverlight site.


Share This Post it! digg it! reddit! technorati! yahoo!