ResourceReferenceKeyNotFoundException declared on Dictionary.xaml

陌路散爱 提交于 2020-01-06 07:00:47

问题


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:

The Default.xaml is my default dictionary.

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


回答1:


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



来源:https://stackoverflow.com/questions/14750583/resourcereferencekeynotfoundexception-declared-on-dictionary-xaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!