如何导入具有 1 个 ResourceDictionary 的合并字典的深层层次结构? [英] How can I import a deep hierarchy of merged dictionaries with 1 ResourceDictionary?

查看:42
本文介绍了如何导入具有 1 个 ResourceDictionary 的合并字典的深层层次结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从依赖类库项目中合并字典,但找不到资源键.注意:我正在使用 Microsoft 提供的此 Connect 错误解决方法 应该允许框架进行足够深的搜索以找到嵌套资源.这似乎不起作用.

I am attempting to merge in dictionaries from a dependent class library project, but the resource keys can't be found. Note: I am using this Connect bug workaround from Microsoft which is supposed to allow the framework to search deep enough to find the nested resources. This does not appear to be working.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/ResourceLibrary.xaml" />
            <ResourceDictionary>
                <Style TargetType="{x:Type Line}" /> <!-- workaround from MS to allow for this -->
                <Main:AppBootstrapper x:Key="bootstrapper" /> <!-- CaliburnMicro bootstrapper, unsure if this is relevant -->
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

ResourceLibrary.xaml 内

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="DefaultColorTheme.xaml" />
        <!-- ...snip... -->
        <ResourceDictionary Source="TransitionControl.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

这样做时,它找不到资源键.如果我从该类库中手动合并每个字典,它工作正常.IMO,这开始违背将资源抽象到外部程序集的目的.

When doing this, it cannot find the resource keys. If I merge each dictionary in manually from that class library, it works fine. This, IMO, begins to defeat the purpose of abstracting resources out to an external assembly.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/DefaultColorTheme.xaml" />
            <ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/Images.xaml" />
            <ResourceDictionary Source="/MyApplication.ControlLibrary;component/ResourceDictionaries/FontIcons.xaml" />      

            <ResourceDictionary>
                <Style TargetType="{x:Type Line}" />
                <Main:AppBootstrapper x:Key="bootstrapper" />
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

我是否将虚拟隐式样式放在了错误的位置?有什么事情没有在这里加起来.感谢您的关注.

Have I placed the dummy implicit style in the wrong place? Something isn't adding up here. Thanks for looking.

推荐答案

我玩了 3 天,艰难地学会了这一点.

I've learned this the hard way by playing around with it for 3 days.

不要制作非常深的结构.有一个只使用其他词典的主词典.该应用不应访问其他人的任何内容.

do not make really deep structures. Have a main dictionary that is just using other dictionaries. The app is not supposed to access anything from the others.

但关键是按正确的顺序引用它们.如果您加载一个 RD,其中一个内容使用了另一个尚未加载的内容,则它将无法工作.顺序真的很重要.

But the crucial thing is to reference them in the right order. it wont work if you load a RD where one of it's contents use something from another one that is not already loaded. The order is truly crucial.

使用 WPF Inspector 会对您有很大帮助,因为它可以跟踪 WPF 应用程序中的所有内容.

Using WPF Inspector will help you a lot since it makes it possible to track everything donw in an WPF app.

这篇关于如何导入具有 1 个 ResourceDictionary 的合并字典的深层层次结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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