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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
37 additions and
1 deletions
-
src/Avalonia.Controls/Presenters/PanelContainerGenerator.cs
-
tests/Avalonia.Controls.UnitTests/ItemsControlTests.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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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() |
|
|
|
{ |
|
|
|
|