每个字典条目必须具有关联的密钥

时间:2013-09-07 08:17:58

标签: c# xaml

我有一个继承名为IDictionary的{​​{1}}的班级 另外,我还有一个名为ResourceDictionary的属性DictionaryKeyProperty的类 Style名为DictionaryKeyProperty

XAML文件内容:

TargetType

提供错误 <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.

我做错了什么? 我怎么解决这个问题?

P.S。:我想制作一个包含像WPF这样的依赖系统的轻型框架。

1 个答案:

答案 0 :(得分:1)

XAML编译器抱怨,因为您的样式定义缺少Key属性。

将其更改为:

<Style x:Key="someKey" TargetType="test" />

..会让错误消失但是因为我怀疑你想要为你的控件声明一个默认样式,所以需要你总是使用

引用该样式
<Test Style="{StaticResource someKey}" />

这可能不是你的想法。

您能否使用“test”类的代码更新问题?

相关问题