{
resources = resources ?? new Dictionary<string, object>();
foreach (KeyValuePair<string, object> 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<Style>(resources[res.Key] as List<Style>);
mergedClassStyles.AddRange(res.Value as List<Style>);
resources[res.Key] = mergedClassStyles;
}
+ }
}
var app = element as Application;
if (app != null && app.SystemResources != null)