4
votes

I have set up a Prism project with one module. In the module I have defined some views. I want to use a ResourceDictionary to style UI elements.

However...if I include the following code in the View1.xaml i get the following error

Warning 1 The designer does not support loading dictionaries that mix 'ResourceDictionary' items without a key and other items in the same collection. Please ensure that the 'Resources' property does not contain 'ResourceDictionary' items without a key, or that the 'ResourceDictionary' item is the only element in the collection.

Here is the code:

<UserControl.Resources>                
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../Resources/ResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>        
    </ResourceDictionary>
</UserControl.Resources>

If I include the code in the App.xaml file the style looks applied in the designer, but when I run the project i get the following error:

Cannot find a Resource with the Name/Key

Do you have any useful advices how to use ResourceDictionary styles with Prism and MVVM?

Thanks

1
Do you have a ressource without key in the dictionary? - PVitt
No...all the resources have a key. However...i now added the ResourceDictionary inside the Grid..like Grid.Resources and the thing works..but I don't understand why it does not allow this in the Usercontrol.Resources - Aljaz Vidmar
Moving it from UserControl.Resources to Grid.Resources also worked for me, though I too have no idea why. - John
Ensure that each resource in your ResourceDictionary.xaml has a x:key or a x:Name attribute and check that those names or keys only contains letters, decimal digits and _ - JackNova
Furthermore try to check for key uniqueness - JackNova

1 Answers