Browse Source
Merge pull request #11761 from Gillibald/textBlockVisualChildren
[TextBlock] Reset VisualChildren when Inlines change
pull/11778/head
Benedikt Stebner
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
34 additions and
11 deletions
-
src/Avalonia.Controls/TextBlock.cs
-
tests/Avalonia.Controls.UnitTests/TextBlockTests.cs
|
|
|
@ -668,17 +668,7 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
if (HasComplexContent) |
|
|
|
{ |
|
|
|
if (_textRuns != null) |
|
|
|
{ |
|
|
|
foreach (var textRun in _textRuns) |
|
|
|
{ |
|
|
|
if (textRun is EmbeddedControlRun controlRun && |
|
|
|
controlRun.Control is Control control) |
|
|
|
{ |
|
|
|
VisualChildren.Remove(control); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
VisualChildren.Clear(); |
|
|
|
|
|
|
|
var textRuns = new List<TextRun>(); |
|
|
|
|
|
|
|
|
|
|
|
@ -115,6 +115,39 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Changing_Inlines_Should_Reset_InlineUIContainer_VisualParent_On_Measure() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) |
|
|
|
{ |
|
|
|
var target = new TextBlock(); |
|
|
|
|
|
|
|
var control = new Control(); |
|
|
|
|
|
|
|
var run = new InlineUIContainer(control); |
|
|
|
|
|
|
|
target.Inlines.Add(run); |
|
|
|
|
|
|
|
target.Measure(Size.Infinity); |
|
|
|
|
|
|
|
Assert.True(target.IsMeasureValid); |
|
|
|
|
|
|
|
Assert.Equal(target, control.VisualParent); |
|
|
|
|
|
|
|
target.Inlines = null; |
|
|
|
|
|
|
|
Assert.Null(run.Parent); |
|
|
|
|
|
|
|
target.Inlines = new InlineCollection { new Run("Hello World") }; |
|
|
|
|
|
|
|
Assert.Null(run.Parent); |
|
|
|
|
|
|
|
target.Measure(Size.Infinity); |
|
|
|
|
|
|
|
Assert.Null(control.VisualParent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void InlineUIContainer_Child_Schould_Be_Arranged() |
|
|
|
{ |
|
|
|
|