无法从引用的项目中合并 ResourceDictionary [英] Unable to merge ResourceDictionary from a referenced project

查看:34
本文介绍了无法从引用的项目中合并 ResourceDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个程序集,每个程序集都提供一组通用的样式和资源,我想将它们包含在我的应用程序中.我在我的 App.xaml 中使用合并字典来加载它们,并且在运行时它们很好.不幸的是,这些资源不会在设计时加载,我的错误窗口会填满有关无法解析资源的消息,并为我提供一个不代表实际显示内容的 UI.

I have two assemblies that each provide a common set of styles and resources that I want to include in my application. I'm using merged dictionaries in my App.xaml in order to load them, and at runtime they were just fine. Unfortunately, these resources won't load at design time, filling my Errors window with messages about unresolvable resources and giving me a UI that doesn't represent what will actually appear.

这是我现在的 App.xaml:

This is my App.xaml as it stands right now:

<Application x:Class="ClientDebug.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             >
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Dai.Common;component/Xaml/Common.xaml" />
                <ResourceDictionary Source="/Dai.DevExpress;component/Xaml/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

对于这两个合并的词典,我在错误"窗口中收到以下错误:

For both of these merged dictionaries, I get the following errors in my Errors window:

Error   11  An error occurred while finding the resource dictionary "/Dai.Common;component/Xaml/Common.xaml".   C:\DevProjects\Core Application\ClientDebug\App.xaml    12  17  ClientDebug
Error   12  An error occurred while finding the resource dictionary "/Dai.DevExpress;component/Xaml/Styles.xaml".   C:\DevProjects\Core Application\ClientDebug\App.xaml    13  17  ClientDebug

显然缺少有用的信息.同样,它们在运行时加载,正如您所期望的那样,但在设计时没有可用的资源.

Which are obviously short on helpful information. Again, they load at runtime just as you'd expect, but none of the resources are available at design time.

推荐答案

从几天前开始,我每次开始一个新的 WPF 项目或使用旧的项目时都会遇到这个问题.我开始提出一个问题来寻求帮助,结果它在我的测试解决方案中消失了!好像 Visual Studio 不太稳定,谁知道?

I have this every time I start a new WPF project or work with an old one ever since a few days ago. I started a question to ask for help on it, only for it to disappear on me on a test Solution! Seems Visual Studio's not very stable, who knew?

问题的核心是 Xaml 设计器不允许您从仅您的应用程序项目引用您的解决方案中的其他项目.解决方法是将所有内容移动到一个库中,让应用程序做的只是在代码中将控制权交给它.不优雅和失去 App.Xaml 是一件很艰难的事情,但总比等待 Visual Studio 神奇地搞定要好得多.

The core of the problem is that the Xaml designer isn't allowing you to make references to other Projects in your Solution from your Application Project only. The workaround is to move everything into a Library and have the Application do little more than hand off control to it in code. Inelegant and the loss of App.Xaml is very tough, but it's much better than waiting for Visual Studio to magically figure it all out.

这篇关于无法从引用的项目中合并 ResourceDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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