Combining ResourceDictionary with MVVM Light or localization files

I have several Windows Phone 7 apps up and running with both MVVM Light and localized resources without a problem. When I decided to take it a step further and try to add my custom ResourceDictionary reference in the App.xaml file, things blew up.

<Application.Resources>
    <!--Global View Model Locator-->
    <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
    <localization:EvaResources x:Key="LocStrings" />

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/EvaResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

I’m getting the following error in Visual Studio 2010: “The type 'ResourceDictionary' is inside a ResourceDictionary and does not have a key.”, and Expression Blend 4 says: “Each dictionary entry must have an associated key.”

To solve it, you have to move both the MVVM Light Locator and localized resources references in their own ResourceDictionary and add this to the MergedDictionaries tag.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/EvaResourceDictionary.xaml"/>
            <ResourceDictionary>
                <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
                <localization:EvaResources x:Key="LocStrings" />
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
Licensed under CC BY-NC-SA 4.0; code samples licensed under MIT.
comments powered by Disqus
Built with Hugo - Based on Theme Stack designed by Jimmy