装载合并的ResourceDictionary从不同的汇编失败 [英] Loading merged ResourceDictionary from different assembly fails

查看:152
本文介绍了装载合并的ResourceDictionary从不同的汇编失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把我所有的应用程序的ResourceDictionaries成一个单独的程序,并合并成一个ResourceDictionary中我想包括在我的应用程序的资源:

I've put all of my application's ResourceDictionaries into a separate assembly and merged them into one ResourceDictionary which I want to include as a resource in my application:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="InputStyles.xaml"/>
        <ResourceDictionary Source="DataGridStyles.xaml"/>
        <ResourceDictionary Source="ComboboxStyles.xaml"/>
        <ResourceDictionary Source="CheckboxStyles.xaml"/>
        <ResourceDictionary Source="TabControlStyles.xaml"/>
        <ResourceDictionary Source="ButtonStyles.xaml"/>
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

声明的资源:

Declaring resource:

<Window.Resources>
    <ResourceDictionary Source="pack://application:,,,/StyleAssembly;component/Styles.xaml"/>
</Window.Resources>

纵观所有的控件都显示来自文件的样式,但在VS设计师,当我尝试启动,我发现了以下错误的应用程序:

Looking at the designer in VS all controls are displayed with the styles from the files but when I try to start the application I'm getting the following error:

无法找到资源inputstyles.xaml'。

"Cannot locate resource 'inputstyles.xaml'."

生成操作设置为页的所有文件和构建这两个项目成功。我究竟做错了什么?

The build action is set to 'Page' for all files and the build for both projects succeeds. What am I doing wrong?

推荐答案

构建如果你愿意做一些腿部工作的行动应被定义为资源或内容

您必须将资源定义为项目的一部分,作为一个资源   建设行动。如果包含在项目中作为资源的.xaml文件   资源,则不需要所述资源文件复制到输出   目录,资源已经包括在编译   应用。您还可以使用内容生成操作的,但是你必须再   将文件复制到输出目录,并部署资源   在可执行相同的路径关系的文件。

Your resource must be defined as part of the project as a Resource build action. If you include a resource .xaml file in the project as Resource, you do not need to copy the resource file to the output directory, the resource is already included within the compiled application. You can also use Content build action, but you must then copy the files to the output directory and also deploy the resource files in the same path relationship to the executable.

这篇关于装载合并的ResourceDictionary从不同的汇编失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆