Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am programming w Windows 8.1 App using C# and the MVVM-Light Toolkit from GalaSoft.

All I have is the code below:

<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> 

or

    <vm:ViewModelLocator x:Key="Locator" xmlns:vm="using:Scedule.ViewModel" />

Can anyone tell me what the problem here is?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
691 views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...