每一个辞条必须有一个相关的关键属性 [英] Each Dictionary entry must have an associated key attribute

查看:366
本文介绍了每一个辞条必须有一个相关的关键属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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

这篇关于每一个辞条必须有一个相关的关键属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆