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>
In a related question i gave an answer which shows how one could create a generic dictionary in XAML without the XAML 2009 features using a custom Markup Extension instead.
If the keys and values are strings, you can use ListDictionary or HybridDictionary.
For example:
Try something like this:
use this namespace:
xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
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#
XAML