diff --git a/src/Avalonia.Controls/Documents/InlineCollection.cs b/src/Avalonia.Controls/Documents/InlineCollection.cs index f3d32d92d3..d98d15b3f1 100644 --- a/src/Avalonia.Controls/Documents/InlineCollection.cs +++ b/src/Avalonia.Controls/Documents/InlineCollection.cs @@ -159,6 +159,8 @@ namespace Avalonia.Controls.Documents { foreach (var child in this) { + child.InlineHost = newValue; + if (child is not InlineUIContainer container) { continue; diff --git a/src/Avalonia.Controls/Documents/Span.cs b/src/Avalonia.Controls/Documents/Span.cs index 7931ecbbde..a1d35d06c7 100644 --- a/src/Avalonia.Controls/Documents/Span.cs +++ b/src/Avalonia.Controls/Documents/Span.cs @@ -77,9 +77,6 @@ namespace Avalonia.Controls.Documents private void OnInlinesChanged(InlineCollection? oldValue, InlineCollection? newValue) { - void OnInlinesInvalidated(object? sender, EventArgs e) - => InlineHost?.Invalidate(); - if (oldValue is not null) { oldValue.LogicalChildren = null; @@ -93,6 +90,11 @@ namespace Avalonia.Controls.Documents newValue.InlineHost = InlineHost; newValue.Invalidated += OnInlinesInvalidated; } + + return; + + void OnInlinesInvalidated(object? sender, EventArgs e) + => InlineHost?.Invalidate(); } } } diff --git a/tests/Avalonia.Controls.UnitTests/TextBlockTests.cs b/tests/Avalonia.Controls.UnitTests/TextBlockTests.cs index a260757d5f..bd2532afba 100644 --- a/tests/Avalonia.Controls.UnitTests/TextBlockTests.cs +++ b/tests/Avalonia.Controls.UnitTests/TextBlockTests.cs @@ -205,6 +205,23 @@ namespace Avalonia.Controls.UnitTests } } + [Fact] + public void Changing_InlineHost_Should_Propagate_To_Nested_Inlines() + { + using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) + { + var target = new TextBlock(); + + var span = new Span { Inlines = new InlineCollection { new Run { Text = "World" } } }; + + var inlines = new InlineCollection{ new Run{Text = "Hello "}, span }; + + target.Inlines = inlines; + + Assert.Equal(target, span.InlineHost); + } + } + [Fact] public void Changing_Inlines_Should_Reset_VisualChildren() {