wpf 查找资源字典时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14392782/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:39:01  来源:igfitidea点击:

An error occurred while finding the resource dictionary

wpfvisual-studio-2012

提问by Blake Mumford

I have a merged resource dictionary in App.xamlMain assembly, which combines various resource dictionaries from separate assemblies: Common and PresentationLayer.

我在App.xaml主程序集中有一个合并的资源字典,它结合了来自不同程序集的各种资源字典:Common 和 PresentationLayer。

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Common;component/Themes/Button.xaml"/>
            <ResourceDictionary Source="/PresentationLayer;component/DataTemplates/AppointmentsDataTemplates.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

At run time the styles in the resource dictionaries are applied to the controls correctly. However, at design time the styles are not applied and Visual Studio 2012 keeps giving the following error:

在运行时,资源字典中的样式会正确应用于控件。但是,在设计时未应用样式并且 Visual Studio 2012 不断给出以下错误:

An error occurred while finding the resource dictionary "/Common;component/Themes/Button.xaml".

And warning:

并警告:

The resource "BannerButton" could not be resolved.

I came across this postbut the problem persists despite Build Action set to Resource. Also, I did not have this problem when running under Visual Studio 2010 or Expression Blend 4. The Main assembly definitely holds a reference to the Common assembly and I haven't changed the Pack URIs.

我遇到了这篇文章,但尽管构建操作设置为资源,但问题仍然存在。此外,在 Visual Studio 2010 或 Expression Blend 4 下运行时,我没有遇到这个问题。主程序集肯定包含对公共程序集的引用,我没有更改包 URI。

采纳答案by Blake Mumford

This was a known issue with Visual Studio 2012. See this linkat Microsoft Connect. After installing VS2012 Update 1 this issue resolved for me. If you think you're running the most up to date version of VS2012 and still experiencing this issue, make absolutely sure that the update has been applied. I thought I had updated using Windows Update, but then found that I had to tell VS2012 to apply the update. After VS2012 did its thing everything was fine.

这是 Visual Studio 2012 的一个已知问题。请参阅Microsoft Connect 上的此链接。安装 VS2012 Update 1 后,这个问题为我解决了。如果您认为您运行的是最新版本的 VS2012 并且仍然遇到此问题,请务必确保已应用更新。我以为我已经使用 Windows Update 进行了更新,但后来发现我必须告诉 VS2012 应用更新。在 VS2012 做它的事情之后,一切都很好。

回答by rattler

For VS2017 if assembly is referenced and double-checked that all namings are OK try to close VS and delete .vsdirectory in solution directory. This will cause you to lose all user settings (startup project, WPF designer zoom, etc.) but will fix this.

对于 VS2017,如果引用程序集并仔细检查所有命名是否正常,请尝试关闭 VS 并删除.vs解决方案目录中的目录。这将导致您丢失所有用户设置(启动项目、WPF 设计器缩放等),但会解决此问题。

回答by Casper

If you are using Visual Studio 2017, try to restart your computer. The problem may be solved.

如果您使用的是 Visual Studio 2017,请尝试重新启动计算机。问题可能会得到解决。

回答by Jaya shanmuga pandian

Try the same in Window.Resources, make sure you added namespace when using app.xaml and don't forget to change the buildoption to pagewhere you need to use that app.xaml.

尝试在Window.Resources相同,请确保您使用的App.xaml的时候,不要忘记在改变添加命名空间构建选项页面,你需要使用App.xaml中。