views:

503

answers:

1

Pseudo example:

<Window>
  <Window.Tag>
    <x:Dictionary KeyType="{x:Type sys:String}" ValueType="{x:Type sys:Int32}">
        <sys:DictionaryEntry Entry="{sys:DictionaryEntry Key0, 000}"/>
        <sys:DictionaryEntry Key="key1" Value="111"/>
        <sys:DictionaryEntry>
          <sys:DictionaryEntry.Key>
            <sys:String>Key2<sys:String>
          </sys:DictionaryEntry.Key>          
          <sys:DictionaryEntry.Value>
            <sys:Int32>222</sys:Int32>            
          </sys:DictionaryEntry.Value>
        </sys:DictionaryEntry>
    </x:Dictionary />    
  </Window.Tag>
</Window>
+6  A: 

You can't use the Dictionary<TKey, TValue> class directly in XAML, because there's no way to specify the generic type arguments (it will be possible in the next version of XAML, but it won't be supported in VS2010 WPF designer... at least not in the initial release).

However, you can declare a non-generic class that inherits from Dictionary<TKey, TValue>, and use it in XAML.

C#

public class MyDictionary : Dictionary<string, int> { }

XAML

<Window>
  <Window.Tag>
    <local:MyDictionary>
        <sys:Int32 x:Key="key0">0</sys:Int32>
        <sys:Int32 x:Key="key1">111</sys:Int32>
        <sys:Int32 x:Key="key2">222</sys:Int32>
    </local:MyDictionary />    
  </Window.Tag>
</Window>
Thomas Levesque
What is meant by *it will be possible in the next version of XAML* do you have any clue when they plan to implement it?
Shimmy
@Shimmy : actually, it is already implemented in XAML 2009. Unfortunately VS2010 doesn't support XAML 2009 yet :(
Thomas Levesque
For details, see this video : http://channel9.msdn.com/pdc2008/TL36/ (XAML 2009 new features are presented starting at 7'20)
Thomas Levesque
what do you mean 7'20, is this when I will be 70yo :{
Shimmy
I mean at the position "7 minutes and 20 seconds" in the video
Thomas Levesque