【发布时间】:2011-02-27 20:01:35
【问题描述】:
我见过很多次这种形式的wpf代码示例:
<Window.Resources>
<DataTemplate DataType="{x:Type SomeType}">
<!-- Elements defining the DataTemplate-->
</DataTemplate>
</Window.Resources>
我理解用法,但我不明白为什么这种语法可以:因为 ResourceDictionary 实现了 IDictionary,因此我们添加到 Resource 属性的每个元素都必须指定一个键。现在我知道使用 DictionaryKeyPropertyAttribute,一个类可以提供一个隐式键值 - 但对于 DataTemplate 类,提供的属性是“DataTemplateKey”。我知道这听起来有点琐碎,但这个问题的动机是知道如何使用其他类,即使我之前没有看到使用示例的特权(也许是第 3 方......)。有人吗?
【问题讨论】: