WPF 找不到资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27814477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Cannot locate resource
提问by Nodon
I have a resource file and two views. This views use a resource file
我有一个资源文件和两个视图。此视图使用资源文件
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
And it will work while i dont put one view to the another. In this case i get this error
当我不将一个视图置于另一个视图时它会起作用。在这种情况下,我收到此错误
Cannot locate resource 'dictionary1.xaml'
无法找到资源“dictionary1.xaml”
How to fix it?
如何解决?
回答by Amol Bavannavar
Use Pack Uri's
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Assembly_Name;component/Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
回答by Rang
If Dictionary1.xamlin your project's rootpath, remove '/' before Dictionary1
如果Dictionary1.xaml在您项目的根路径中,请删除 Dictionary1 之前的“/”
<ResourceDictionary Source="Dictionary1.xaml"/>
Or you can use packuri like :
或者你可以使用 packuri 像:
/yourAssemblyName;component/Dictionary1.xaml

