1

ObjectDataProvider在字典上有一个声明:

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

我有一个班级想像这样找到它:

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

但是当它试图找到资源时,它会启动错误

ResourceReferenceKeyNotFoundException

并且找不到我的资源......这里有一张关于我的项目如何划分的图片:

在此处输入图像描述

Default.xaml是我的默认字典。

那么,为什么我找不到我Resources的字典中定义的元素?

4

1 回答 1

2

我需要回答我的问题,因为这是一件很奇怪的事情......

首先,我需要说我必须将 my 添加Dictionary.xaml到 my App.xaml

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

出于某种原因,在我的MainWindow.xaml. 所以我从我的删除它MainWindow.xaml并将它添加到App.xaml,但我无法将它们插入两侧。那是我看不清楚的部分...

于 2013-02-07T17:29:20.737 回答