Allow Merged Dirctionaries hierarchically merging

MakemanMakeman BYMember
edited October 2017 in Xamarin.Forms

[Sorry for links format, I have not permission to post correct links...]
[Moved from "" by suggestion of Paul DiPietro]


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" } };


        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

Full PR

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).

0 votes

Open · Last Updated


Sign In or Register to comment.