Multiple ResourceDictionary with same DataTemplate key?

后端 未结 1 1827
春和景丽
春和景丽 2021-01-03 16:44

I have a ResourceDictionary such as (MyResourceDictionary):



        

        
1条回答
  •  别那么骄傲
    2021-01-03 17:15

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

    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.

    And:

    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.

    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.

    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.

    0 讨论(0)
提交回复
热议问题