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

 

Comments (8)

  1. Robert says:

    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.

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

  3. Daniel Puzey says:

    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&quot;

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

    … 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&quot;

    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"?

  4. 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&quot;        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml&quot;

  5. Daniel Puzey says:

    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&quot;

     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml&quot;>”>http://schemas.microsoft.com/winfx/2006/xaml&quot;>

     <Page.Resources>

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

     </Page.Resources>

    </Page>

    <Page

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

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

     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.

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

  7. 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.

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