【发布时间】:2014-02-05 01:54:16
【问题描述】:
我有一个继承 IDictionary 的类,名为 ResourceDictionary。
另外我还有另一个类,其属性为DictionaryKeyProperty,名为Style。DictionaryKeyProperty 被命名为 TargetType。
XAML 文件内容:
<ResourceDictionary
xmlns="clr-namespace:Test;assembly=Test"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
<Style TargetType="test" />
</ResourceDictionary>
它给出了错误 Each dictionary entry must have an associated key.
public class ResourceDictionary : IDictionary, ICollection, IEnumerable, INameScope, ISupportInitialize
{
...
}
[ContentProperty("Setters"), DictionaryKeyProperty("TargetType")]
public class Style : Sealable, INameScope, IQueryAmbient, IResources
{
private Type _TargetType;
[Ambient]
public Type TargetType
{
get { return _TargetType; }
set
{
CheckSealed();
if (value == null)
throw new ArgumentNullException("value");
_TargetType = value;
}
}
......
}
我做错了什么?
我怎么解决这个问题?
P.S.:我想制作一个包含 WPF 等依赖系统的轻量级框架。
【问题讨论】: