Browse Source
Fix Collection Was Modified exception in VisualLayerManager when a TextBox was added to an AdornerLayer (#14484)
pull/14542/head
Bartosz Korczyński
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
28 additions and
1 deletions
-
src/Avalonia.Controls/Primitives/VisualLayerManager.cs
-
tests/Avalonia.Controls.UnitTests/TextBoxTests.cs
|
|
|
@ -148,8 +148,12 @@ namespace Avalonia.Controls.Primitives |
|
|
|
/// <inheritdoc />
|
|
|
|
protected override Size MeasureOverride(Size availableSize) |
|
|
|
{ |
|
|
|
foreach (var l in _layers) |
|
|
|
for (var index = 0; index < _layers.Count; index++) |
|
|
|
{ |
|
|
|
var l = _layers[index]; |
|
|
|
l.Measure(availableSize); |
|
|
|
} |
|
|
|
|
|
|
|
return base.MeasureOverride(availableSize); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1367,6 +1367,29 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void TextBox_In_AdornerLayer_Will_Not_Cause_Collection_Modified_In_VisualLayerManager() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(Services)) |
|
|
|
{ |
|
|
|
var button = new Button(); |
|
|
|
var root = new TestRoot() |
|
|
|
{ |
|
|
|
Child = new VisualLayerManager() |
|
|
|
{ |
|
|
|
Child = button |
|
|
|
} |
|
|
|
}; |
|
|
|
var adorner = new TextBox { Template = CreateTemplate(), Text = "a" }; |
|
|
|
|
|
|
|
var adornerLayer = AdornerLayer.GetAdornerLayer(button); |
|
|
|
adornerLayer.Children.Add(adorner); |
|
|
|
AdornerLayer.SetAdornedElement(adorner, button); |
|
|
|
|
|
|
|
root.Measure(Size.Infinity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData("A\nBB\nCCC\nDDDD", 0, 0)] |
|
|
|
[InlineData("A\nBB\nCCC\nDDDD", 1, 2)] |
|
|
|
|