From eeb7271c34e3be1d21918f3f184d918b55c0d94a Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 15 Jul 2019 12:35:52 +0200 Subject: [PATCH 1/2] Added failing test for #2584. --- .../Avalonia.Styling.UnitTests/StylesTests.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Avalonia.Styling.UnitTests/StylesTests.cs b/tests/Avalonia.Styling.UnitTests/StylesTests.cs index c033dad0c6..82b6b81759 100644 --- a/tests/Avalonia.Styling.UnitTests/StylesTests.cs +++ b/tests/Avalonia.Styling.UnitTests/StylesTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; +using Avalonia.Controls; using Xunit; namespace Avalonia.Styling.UnitTests @@ -111,5 +112,28 @@ namespace Avalonia.Styling.UnitTests Assert.False(raised); } + + + [Fact] + public void Finds_Resource_In_Merged_Dictionary() + { + var target = new Styles + { + Resources = new ResourceDictionary + { + MergedDictionaries = + { + new ResourceDictionary + { + { "foo", "bar" }, + } + } + } + }; + + var result = target.FindResource("foo"); + + Assert.Equal("bar", result); + } } } From 35bc1b37da6fcb9aa9dda5daa8ab9878993e8df7 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 15 Jul 2019 12:36:22 +0200 Subject: [PATCH 2/2] Call TryGetResource instead of TryGetValue. So that merged dictionaries are searched. Fixes #2584 --- src/Avalonia.Styling/Styling/Styles.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Styling/Styling/Styles.cs b/src/Avalonia.Styling/Styling/Styles.cs index 789bb6ffd3..a4563110a9 100644 --- a/src/Avalonia.Styling/Styling/Styles.cs +++ b/src/Avalonia.Styling/Styling/Styles.cs @@ -180,7 +180,7 @@ namespace Avalonia.Styling /// public bool TryGetResource(object key, out object value) { - if (_resources != null && _resources.TryGetValue(key, out value)) + if (_resources != null && _resources.TryGetResource(key, out value)) { return true; }