Skip to content

Commit 8a43603

Browse files
committed
fix: Fix lazy theme dictionary caching
1 parent 68f1f7d commit 8a43603

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Uno.UI.Tests/Windows_UI_Xaml/Given_ResourceDictionary.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,26 @@ public void When_Default_Theme_Dictionary_Should_Be_Used_After_Removing_Active_T
875875
Assert.IsFalse(dictionary.TryGetValue("TestKey", out _));
876876
}
877877

878+
[TestMethod]
879+
public void When_Lazy()
880+
{
881+
var dictionary = new ResourceDictionary();
882+
var brush = new SolidColorBrush { Color = Colors.Red };
883+
dictionary.TryGetValue("TestKey", out _);
884+
885+
dictionary.ThemeDictionaries.Add("Light", new WeakResourceInitializer(new Application(), o =>
886+
new ResourceDictionary
887+
{
888+
["TestKey"] = new WeakResourceInitializer(o, _ => brush)
889+
}));
890+
891+
892+
// Make sure the cache is updated.
893+
Assert.IsTrue(dictionary.TryGetValue("TestKey", out var testValue));
894+
Assert.AreEqual(brush, testValue);
895+
896+
}
897+
878898
[TestMethod]
879899
public void When_Resource_NotImplemented()
880900
{

src/Uno.UI/UI/Xaml/ResourceDictionary.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ private void Set(in ResourceKey resourceKey, object value, bool throwIfPresent)
249249
{
250250
_hasUnmaterializedItems = true;
251251
_values[resourceKey] = new LazyInitializer(ResourceResolver.CurrentScope, resourceInitializer);
252+
ResourceDictionaryValueChange?.Invoke(this, EventArgs.Empty);
252253
}
253254
else
254255
{

0 commit comments

Comments
 (0)