Allow Merged Dirctionaries hierarchically merging

MakemanMakeman BYMember
edited October 23 in Xamarin.Forms Evolution

[Sorry for links format, I have not permission to post correct links...]
[Moved from "bugzilla.xamarin.com/show_bug.cgi?id=60316" by suggestion of Paul DiPietro]

Summary

WPF and UWP allow to merge dictionaries hierarchically. It is very useful feature which helps to split resources by different logically files.
Current Xamarin.Forms implementation of Merged Dictionaries at master brunch can not merge dictionaries hierarchically.

Just try to run following method on master, current brunch and WPF or UWP for tests.

    public static void MergedDictionariesDeepSublevels()
    {
        var rd0 = new ResourceDictionary();
        var rd1 = new ResourceDictionary { { "Key1", "Level1" } };
        var rd2 = new ResourceDictionary { { "Key2", "Level2" } };

        rd0.MergedDictionaries.Add(rd1);
        rd1.MergedDictionaries.Add(rd2);

        Assert.That(rd0["Key1"], "Level1");
        Assert.That(rd0["Key2"], "Level2"); // <= fail on master, work on WPF or UWP

        //Assert.That(rd0.ContainsKey("Key1"), Is.EqualTo(true));
        //Assert.That(rd0.ContainsKey("Key2"), Is.EqualTo(true));
    }

Fix is very simple, see commit
github.com/xamarin/Xamarin.Forms/commit/e22367ebe90783579fa4a7b3b66da196d41a1960

Full PR
github.com/xamarin/Xamarin.Forms/pull/1218

API Changes

There is not API changes, only removal of restrictions the current implementation.

Intended Use Case

Usually I group different types of resources by files, for example: Colors.xaml=>Converters.xaml=>Paints.xaml=>Templates.xaml=>Styles.xaml=>App.xaml

At the current moment I use own Customized Merged Dictionary for Xamarin Forms, but it is implementation is not so beautiful (direct coping merged values into root dictionary).
github.com/Makeloft/Ace/blob/master/Ace.Zest/Markup/ResourceDictionary.cs

0
0 votes

Open · Last Updated

Posts

Sign In or Register to comment.