每个字典条目必须有一个关联的键属性 [英] Each Dictionary entry must have an associated key attribute
问题描述
我正在使用 C# 和 GalaSoft 的 MVVM-Light 工具包对 Windows 8.1 应用程序进行编程.
I am programming w Windows 8.1 App using C# and the MVVM-Light Toolkit from GalaSoft.
我只有以下代码:
<Application.Resources>
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:Scedule.ViewModel" />
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resource Dictionaries/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
出现错误每个字典条目必须有一个关联的键属性",并且只有在我删除时才会消失
The error "Each Dictionary entry must have an associated key attribute" occurs and only disappears when I either remove
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resource Dictionaries/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
或
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:Scedule.ViewModel" />
谁能告诉我这里的问题是什么?
Can anyone tell me what the problem here is?
推荐答案
注意 Application.Resources
需要一个 ResourceDictionary
的实例,所以你必须做这样的事情:
Note that Application.Resources
requires an instance of ResourceDictionary
, so you have to do something like this:
<Application.Resources>
<ResourceDictionary>
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:Scedule.ViewModel" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resource Dictionaries/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
所以这并不奇怪,也不是错误.如果你希望你的 ResourceDictionary
被当作一个资源,你当然必须为它提供一些 Key
,但是在这种情况下你真的想分配一个 Key
的实例code>ResourceDictionary 到 Application.Resources
So it's not strange at all, it's also not a bug. If you want your ResourceDictionary
to be treated as a resource, you of course have to provide some Key
for it, however in this case you really want to assign an instance of ResourceDictionary
to the Application.Resources
这篇关于每个字典条目必须有一个关联的键属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!