Welcome to MSDN Blogs Sign in | Join | Help

Lester's WPF blog


Simple, easy & beautiful

News

Xaml 2009 Features: Built in Types

In Xaml2009, we have built-in support for common CLR types which simplifies authoring. So rather than specifying something like

<s:String xmlns:s="clr-namespace:System;assembly=mscorlib"> Foo </s:String>

We can use the notation <x:String > Foo </s:String>

The list of types supported is below:

     <x:String>

     <x:Char>

     <x:Single>

     <x:Double>

     <x:Boolean>

     <x:Byte>

     <x:Int16>

     <x:Int32>

     <x:Int64>

     <x:Decimal>

     <x:Object>

     <x:Uri>

     <x:TimeSpan>

     <x:Array>

One thing to note is wrt WPF this will work only in loose Xaml. This means that these features cannot be used within Cider\Blend. Rob has a post clarifying the absence of tooling support.

Now you get the slight change in title J

[This is part of a series on New WPF\XAML Features] 

 

Share this post

 

Posted: Thursday, November 05, 2009 3:52 PM by llester

Comments

Robert said:

Dude, WTF... I thought the whole reasoning with using Xml for UI was toolability, and, ironically, the tools are by far the worst part of the WPF experience.

# November 5, 2009 9:32 AM

llester said:

Robert, we understand that this is not ideal. Please read the clarifying post\comments by Rob http://blogs.windowsclient.net/rob_relyea/archive/2009/05/20/yes-xaml2009-isn-t-everywhere-yet.aspx

# November 5, 2009 10:54 AM

Daniel Puzey said:

That's a strange feature...

The only reason using <x:string> works like that is because you declare the namespace in a parent tag.  Most xaml files by default will start something like this:

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

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

... which is the only reason the unqualified "x:" namespace will work.

If you add the "xmlns:s" declaration to your root element, then your unwieldy example becomes no heavier than the new alternative:

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

xmlns:s="clr-namespace:System;assembly=mscorlib">

...

<s:String> Foo </s:String>

...

And the tools support that just fine, don't they?

I'm not sure what this adds/improves beyond the single missing namespace ref - is there something in the new tags that improves parsing/construction of the objects?  Or is this really just changing an "s" to an "x"?

# November 6, 2009 3:59 AM

llester said:

Daniel, the xaml generated by tools like cider and Blend always have the follows namespaces declared by default (and not just the first one)

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

# November 6, 2009 5:55 AM

Daniel Puzey said:

Sorry Lester, I realise that - I omitted the namespace more for brevity than anything else.

I think my point is still reasonable, though.  Is there a significant difference between these two (more complete) examples?

<Page

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

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

 <Page.Resources>

   <x:String x:Key="foo">Bar</x:String>

 </Page.Resources>

</Page>

<Page

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

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

 xmlns:s="clr-namespace:System;assembly=mscorlib">

 <Page.Resources>

   <s:String x:Key="foo">Bar</s:String>

 </Page.Resources>

</Page>

I was just wondering if there are any other benefits beyond a single missing namespace reference.

# November 6, 2009 9:44 AM

llester said:

as mentioned, it is an improvement in the authoring experience.

# November 6, 2009 10:04 AM

Josh Einstein said:

What would have been a real improvement would be the ability to include multiple namespaces in the default namespace. Or some project-wide mappings so I don't have to junk up every xaml file with the same mappings.

# November 28, 2009 7:32 PM

llester said:

Thats good feedback John. We'll consider it for future releases.

# November 30, 2009 12:16 PM
New Comments to this post are disabled
Page view tracker