Browse Source

Merge pull request #13019 from AvaloniaUI/fixes/itemscontrol-logical-child-removal

Fix ItemsControl logical child removal
pull/13069/head
Max Katz 2 years ago
committed by GitHub
parent
commit
b2f2c49a19
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/Avalonia.Controls/Presenters/PanelContainerGenerator.cs
  2. 35
      tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs

3
src/Avalonia.Controls/Presenters/PanelContainerGenerator.cs

@ -68,9 +68,10 @@ namespace Avalonia.Controls.Presenters
{
var c = children[index + i];
itemsControl.RemoveLogicalChild(children[i + index]);
if (!c.IsSet(ItemIsOwnContainerProperty))
{
itemsControl.RemoveLogicalChild(children[i + index]);
generator.ClearItemContainer(c);
}
}

35
tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs

@ -513,6 +513,41 @@ namespace Avalonia.Controls.UnitTests
Assert.Same(before, after);
}
[Fact]
public void Control_Item_Should_Be_Removed_From_LogicalChildren()
{
using var app = Start();
var item = new Border();
var items = new ObservableCollection<Control>();
var target = CreateTarget(itemsSource: items);
items.Add(item);
items.Remove(item);
Assert.Empty(target.LogicalChildren);
}
[Fact]
public void Control_Item_Should_Be_Removed_From_LogicalChildren_Virtualizing()
{
using var app = Start();
var item = new Border();
var items = new ObservableCollection<Control>();
var itemsPanel = new FuncTemplate<Panel?>(() => new VirtualizingStackPanel());
var target = CreateTarget(
itemsPanel: itemsPanel,
itemsSource: items);
items.Add(item);
Layout(target);
items.Remove(item);
Assert.Empty(target.LogicalChildren);
}
[Fact]
public void Should_Clear_Containers_When_ItemsPresenter_Changes()
{

Loading…
Cancel
Save