具有相同 DataTemplate 键的多个 ResourceDictionary? [英] Multiple ResourceDictionary with same DataTemplate key?

查看:38
本文介绍了具有相同 DataTemplate 键的多个 ResourceDictionary?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ResourceDictionary,例如 (MyResourceDictionary):

I have a ResourceDictionary such as (MyResourceDictionary):

<ResourceDictionary xmlns
        .....
        >

        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="SeriesTwo.xaml" />
        </ResourceDictionary.MergedDictionaries>

        <DataTemplate x:Key="SeriesDetailedInformation">
            <StackPanel>
                ......content...
            </StackPanel>
        </DataTemplate>
</ResourceDictionary>

SeriesTwo.xaml 看起来像这样,并且还有同名的 DataTemplate

SeriesTwo.xaml looks like this and also has the DataTemplate with the same name

<ResourceDictionary xmlns=
        .....
        >
        <DataTemplate x:Key="SeriesDetailedInformation">
            <DataGrid>
                ......content...
            </DataGrid>
        </DataTemplate>
</ResourceDictionary>

在我的视图页面上,使用了哪个 SeriesDetailedInformation 数据模板?这是否取决于我在页面上首先引用的资源字典?

On my view page, which SeriesDetailedInformation data template gets used? Does it depend on which resource dictionary I reference first on my page?

也感谢有关此主题的任何好的链接和其他阅读材料.

Any good links and other reading material regarding this topic is also appreciated.

推荐答案

来自 此页面 似乎与您的问题相关:

A couple of things from this page seem relevant to your question:

MergedDictionaries 集合中的查找行为会搜索最后添加的 ResourceDictionary 首先,搜索停止找到请求的密钥.换句话说,检索逻辑从合并后的资源字典集合是后进先出.

Lookup behavior within the MergedDictionaries collection searches the last-added ResourceDictionary first, and the search stops as soon as a requested key is found. In other words, the retrieval logic from the collection of merged resource dictionaries is last in, first out.

还有:

合并字典中的资源在资源中占据一个位置紧跟在主要资源范围之后的查找范围将它们合并到字典中.

Resources in a merged dictionary occupy a location in the resource lookup scope that is just after the scope of the main resource dictionary they are merged into.

由此,我认为将首先使用您的主词典中定义的 DataTemplate,然后是 SeriesTwo,然后是在 SeriesTwo 之前/之上引用的任何内容.

From this I gather that the DataTemplate defined in your main dictionary would be used first, then SeriesTwo, and any referenced before/above SeriesTwo after that.

另外,为什么不试试看会发生什么?我维护了一个我称之为DumbCrapTestApp"的解决方案,当我对某些东西的工作原理感到好奇时,我会在其中测试这样的东西.它有一个控制台应用程序,当我只需要在语言中测试某些东西时,还有一个 WPF 和一个 Silverlight 应用程序,当我想在那里尝试一些东西时.如果我需要一个 WinForms 应用程序,我只需添加一个并在那里做我的事情.我只需将我想测试的任何代码放入相关应用程序,将其设置为我的启动项目,然后我就走了.这对于弄清楚这些小事情真的很有用,我什至用它来澄清和验证答案,然后再将它们发布到 SO 上.

Also, why not just try it out and see what happens? I maintain a solution I call "DumbCrapTestApp" where I test stuff like this when I'm curious about how something works. It has a console app for when I just need to test something within the language, and a WPF and a Silverlight app for when I want to try something there. If I needed a WinForms app, I'd just add one and do my thing there. I simply put whatever code I want to test into the relevant app, set it as my Startup Project, and away I go. It's really useful for figuring out these little things and I've even used it to get clarification and verify answers before I post them here on SO.

这篇关于具有相同 DataTemplate 键的多个 ResourceDictionary?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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