Browse Source

Fixes/inline host change propagation (#14914)

* Add failing test

* Propagate InlineHost to children
release/11.1.0-beta2
Benedikt Stebner 2 years ago
committed by Max Katz
parent
commit
1ade5af20d
  1. 2
      src/Avalonia.Controls/Documents/InlineCollection.cs
  2. 8
      src/Avalonia.Controls/Documents/Span.cs
  3. 17
      tests/Avalonia.Controls.UnitTests/TextBlockTests.cs

2
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;

8
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();
}
}
}

17
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()
{

Loading…
Cancel
Save