问题描述
我使用C#和GalaSoft的MVVM光强工具包编程W¯¯的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
要求<$ C的一个实例$ C> 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中
被视为一种资源,你当然必须提供一些键
它,但是在这种情况下,你真的想 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
这篇关于每一个辞条必须有一个相关的关键属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!