C# ResourceReferenceKeyNotFoundException在Dictionary.xaml上声明
我在字典上声明了一个C# ResourceReferenceKeyNotFoundException在Dictionary.xaml上声明,c#,wpf,visual-studio-2010,C#,Wpf,Visual Studio 2010,我在字典上声明了一个ObjectDataProvider: <ObjectDataProvider x:Key="Resources" ObjectType="{x:Type const:CultureResources}" MethodName="GetResourceInstance"/> 但是当它试图找到资源时,它会启动错误 ResourceReferenceKeyNotFoundException 找不到我的资源。。。在这里,您可
ObjectDataProvider
:
<ObjectDataProvider x:Key="Resources"
ObjectType="{x:Type const:CultureResources}"
MethodName="GetResourceInstance"/>
但是当它试图找到资源时,它会启动错误
ResourceReferenceKeyNotFoundException
找不到我的资源。。。在这里,您可以看到我的项目是如何划分的:
Default.xaml
是我的默认字典
那么,为什么我找不到字典中定义的
资源元素呢?我需要回答我的问题,因为这是一件很奇怪的事情
首先,我需要说我必须将我的Dictionary.xaml
添加到我的App.xaml
:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../themes/Default.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
出于某种原因,在我的MainWindow.xaml
上调用它是不够的。因此,我从我的main window.xaml
中删除了它,并将其添加到App.xaml
,但我无法将它们插入两侧。这是我看不清楚的部分…非常感谢,解决了我的问题(完全相同)。遗憾的是,WPF没有资源“漫游”的调试器来检查是否所有定义的资源都被扫描。
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../themes/Default.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>