Frank La Vigne

Fear and Loathing in .NET

MVP Logo
Tablet PC MVP

Social Networks

Subscription Options

Add to Google

Subscribe in Bloglines

My Links


Post Categories

Archives

Image Galleries


GamerTag

Dev Community Events

Blog Stats

 

News


Blog Roll

Favorite Sites

Gadget Blogs

Tablet PC Links

A Quick Note on XAML Namespaces in Silverlight/WPF

In my last two blog posts, I wrote about using the export plug-in for Adobe Illustrator developed by Mike Swanson.

Specifically, I'd like to call attention to this screenshot:

wikipedia7 by you.

The blogosphere is self-correcting and Pete Brown pinged me to tell me that the namespaces are woefully out of date.

I never paid much attention to the root elements exported from the plug-in, as I would copy and paste the child elements in into a control class I had stubbed out before doing my artwork.

This way, I have more control over the structure of the resulting XAML and I know where my stuff ends and the artworks begins.

But in case you don't follow my particular style of workflow, keep this in mind.

What's in a Namespace?

For some reason, the namespaces the plug-in uses have not been updated since the days of Silverlight 1 and 1.1.

The Silverlight formatted XAML export files will load just fine into Blend, but you never know what nasty surprises await you if you leave them in there.

The WPF formatted XAML file will load up just fine in a WPF project and by double clicking the file in explorer.

What Could Go Wrong?

Certainly, nothing serious, but you'll be in for a bit of frustration.

If you try to load that same file in Silverlight, however, you'll encounter some problems: The XAML parser in Silverlight 2 has no idea what a ViewBox element is and will throw an exception.

Silverlight 3 now includes ViewBox, but that control lives amongst the extended System.Windows.Controls and won't work unless you manually add the appropriate namespace. Otherwise, the parser will voice its unhappiness and throw an exception.

Recommended Namespaces to Use

The more preferred approach now is to use the 2006 namespaces, as they are the same used by WPF.

This makes the XAML more portable between WPF and Silverlight.

If you have any doubt about which namespace/headers to use, create a new solution in Visual Studio and/or Blend and take a look at the root element of default control created for you by the template.

In both Blend 3 (Target: Silverlight 3)  and Blend 2 (Target: Silverlight 2), the namepaces are as follows:

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

My Recommendation

I'd recommend copying and pasting out only the elements from the imported artwork that you need.

It lets you have control over what goes into your project and it gives you the opportunity to know where the boundaries are between imported artwork and code.

 

posted on Sunday, May 03, 2009 7:55 PM