从不同的程序集中加载合并的 ResourceDictionary 失败 [英] Loading merged ResourceDictionary from different assembly fails

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

问题描述

我已将应用程序的所有 ResourceDictionary 放入一个单独的程序集中,并将它们合并到一个 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>

声明资源:

<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天全站免登陆