Sonhja
Sonhja

Reputation: 8448

ResourceReferenceKeyNotFoundException declared on Dictionary.xaml

I have an ObjectDataProvider declared on a dictionary:

    <ObjectDataProvider x:Key="Resources"
        ObjectType="{x:Type const:CultureResources}" 
        MethodName="GetResourceInstance"/>

And I have a class that wants to find it like this:

m_provider = (ObjectDataProvider) App.Current.FindResource("Resources");

But when it tries to find the Resource, it launches the error

ResourceReferenceKeyNotFoundException

And can't find my resource... Here you have an image on how my project is divided:

enter image description here

The Default.xaml is my default dictionary.

So, why I can't find my Resources element defined on my dictionary?

Upvotes: 1

Views: 475

Answers (1)

Sonhja
Sonhja

Reputation: 8448

I need to answer my question, because it was such a weird thing...

At first, I need to say that I had to add my Dictionary.xaml to my App.xaml:

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

For some reason, it wasn't enough to call it on my MainWindow.xaml. So I erased it from my MainWindow.xaml and added it to App.xaml, but I couldn't have them inserted in both sides. That was the part that I couldn't see clearly...

Upvotes: 2

Related Questions