Browse Source

Merge pull request #6732 from AvaloniaUI/fixes/6729-itemsrepeater-reassign-items

ItemsRepeater: unsubscribe from ItemsSourceView before disposing it.
release/0.10.9
Max Katz 4 years ago
committed by Dan Walmsley
parent
commit
776f3eaa2e
  1. 6
      src/Avalonia.Controls/Repeater/ItemsRepeater.cs
  2. 24
      tests/Avalonia.Controls.UnitTests/ItemsRepeaterTests.cs

6
src/Avalonia.Controls/Repeater/ItemsRepeater.cs

@ -588,14 +588,14 @@ namespace Avalonia.Controls
throw new AvaloniaInternalException("Cannot set ItemsSourceView during layout.");
}
ItemsSourceView?.Dispose();
ItemsSourceView = newValue;
if (oldValue != null)
{
oldValue.CollectionChanged -= OnItemsSourceViewChanged;
}
ItemsSourceView?.Dispose();
ItemsSourceView = newValue;
if (newValue != null)
{
newValue.CollectionChanged += OnItemsSourceViewChanged;

24
tests/Avalonia.Controls.UnitTests/ItemsRepeaterTests.cs

@ -0,0 +1,24 @@
using System.Collections.ObjectModel;
using Xunit;
namespace Avalonia.Controls.UnitTests
{
public class ItemsRepeaterTests
{
[Fact]
public void Can_Reassign_Items()
{
var target = new ItemsRepeater();
target.Items = new ObservableCollection<string>();
target.Items = new ObservableCollection<string>();
}
[Fact]
public void Can_Reassign_Items_To_Null()
{
var target = new ItemsRepeater();
target.Items = new ObservableCollection<string>();
target.Items = null;
}
}
}
Loading…
Cancel
Save