【发布时间】:2013-01-01 19:13:16
【问题描述】:
我在App.xaml Main 程序集中有一个合并的资源字典,它结合了来自不同程序集的各种资源字典: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>
在运行时,资源字典中的样式会正确应用于控件。但是,在设计时未应用样式,并且 Visual Studio 2012 不断给出以下错误:
An error occurred while finding the resource dictionary "/Common;component/Themes/Button.xaml".
还有警告:
The resource "BannerButton" could not be resolved.
我遇到了this post,但尽管构建操作设置为资源,问题仍然存在。另外,在 Visual Studio 2010 或 Expression Blend 4 下运行时,我没有遇到这个问题。主程序集肯定包含对通用程序集的引用,我没有更改包 URI。
【问题讨论】:
-
你试过使用普通的相对路径吗?
-
@DJ 正常相对路径(资源字典在主程序集中的位置)工作正常。
-
@DJ 实际上,Visual Studio 不再抱怨错误,但设计师仍然没有应用样式。
-
是的,因为您提供的路径是基于组件的。即使您解决了这个问题,您的 VS 也无法每次都显示设计师。实际上,您应该使用 Expression Blend 或 kaxaml 工具进行设计。 VS 在这些事情上有点痛苦
-
我遇到了同样的错误:
Source="/MyApp;components/bar.xml",然后意识到我有错别字:它是component(单数)和bar.xaml(XAML,不是 XML)。最终,这适用于将构建操作设置为Resource或Page-- "Page" is just a binary resource -- 并使用以下任一源:pack://application:,,,/MyApp;component/bar.xaml、/PushToTalk;component/bar.xaml、/bar.xaml或只是普通的 olebar.xaml.我正在使用 VS 2012 更新 4。