From fff5b25a1fe8e67891f922879d1f1452e6dd5343 Mon Sep 17 00:00:00 2001 From: Patrick Allwood Date: Mon, 18 Feb 2019 14:57:23 +0000 Subject: [PATCH] Fix dynamic resources in merged dictionaries #3661 (#4993) * fixes #3661 --- Xamarin.Forms.Core/ResourcesExtensions.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Xamarin.Forms.Core/ResourcesExtensions.cs b/Xamarin.Forms.Core/ResourcesExtensions.cs index 1962c3a..9c567ca 100644 --- a/Xamarin.Forms.Core/ResourcesExtensions.cs +++ b/Xamarin.Forms.Core/ResourcesExtensions.cs @@ -15,14 +15,19 @@ namespace Xamarin.Forms { resources = resources ?? new Dictionary(); foreach (KeyValuePair res in ve.Resources.MergedResources) - if (!resources.ContainsKey(res.Key)) - resources.Add(res.Key, res.Value); + { + // If a MergedDictionary value is overridden for a DynamicResource, + // it comes out later in the enumeration of MergedResources + // TryGetValue ensures we pull the up-to-date value for the key + if (!resources.ContainsKey(res.Key) && ve.Resources.TryGetValue(res.Key, out object value)) + resources.Add(res.Key, value); else if (res.Key.StartsWith(Style.StyleClassPrefix, StringComparison.Ordinal)) { var mergedClassStyles = new List