伪示例:
<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>
你不能使用Dictionary<TKey, TValue>
直接在 XAML 中定义类,因为无法指定泛型类型参数(在下一版本的 XAML 中可以实现,但 VS2010 WPF 设计器不支持它......至少在初始版本中不支持)。
但是,您可以声明一个继承自的非泛型类Dictionary<TKey, TValue>
,并在 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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)