diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ResourceDictionaryTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ResourceDictionaryTests.cs
index 939c5319e4..74b6a1e15d 100644
--- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ResourceDictionaryTests.cs
+++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/ResourceDictionaryTests.cs
@@ -74,13 +74,33 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
var xaml = @"
- Red
+
";
var resources = (ResourceDictionary)AvaloniaRuntimeXamlLoader.Load(xaml);
Assert.True(resources.ContainsDeferredKey("Red"));
}
}
+
+ [Fact]
+ public void Item_Added_To_ResourceDictionary_Is_UnDeferred_On_Read()
+ {
+ using (StyledWindow())
+ {
+ var xaml = @"
+
+
+";
+ var resources = (ResourceDictionary)AvaloniaRuntimeXamlLoader.Load(xaml);
+
+ Assert.True(resources.ContainsDeferredKey("Red"));
+
+ Assert.IsType(resources["Red"]);
+
+ Assert.False(resources.ContainsDeferredKey("Red"));
+ }
+ }
[Fact]
public void Item_Is_Added_To_Window_Resources_As_Deferred()
@@ -91,7 +111,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
- Red
+
";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
@@ -113,7 +133,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
- Red
+
@@ -135,7 +155,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
";
var style = (Style)AvaloniaRuntimeXamlLoader.Load(xaml);
@@ -154,7 +174,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
- Red
+
";
var style = (Styles)AvaloniaRuntimeXamlLoader.Load(xaml);
@@ -164,6 +184,60 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
}
}
+ [Fact]
+ public void Item_Can_Be_StaticReferenced_As_Deferred()
+ {
+ using (StyledWindow())
+ {
+ var xaml = @"
+
+
+
+
+
+";
+ var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
+ var windowResources = (ResourceDictionary)window.Resources;
+ var buttonResources = (ResourceDictionary)((Button)window.Content!).Resources;
+
+ Assert.True(windowResources.ContainsDeferredKey("Red"));
+ Assert.True(buttonResources.ContainsDeferredKey("Red2"));
+ }
+ }
+
+ [Fact]
+ public void Item_StaticReferenced_Is_UnDeferred_On_Read()
+ {
+ using (StyledWindow())
+ {
+ var xaml = @"
+
+
+
+
+
+";
+ var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
+ var windowResources = (ResourceDictionary)window.Resources;
+ var buttonResources = (ResourceDictionary)((Button)window.Content!).Resources;
+
+ Assert.IsType(buttonResources["Red2"]);
+
+ Assert.False(windowResources.ContainsDeferredKey("Red"));
+ Assert.False(buttonResources.ContainsDeferredKey("Red2"));
+ }
+ }
+
private IDisposable StyledWindow(params (string, string)[] assets)
{
var services = TestServices.StyledWindow.With(