Browse Source

Fix clearing nested selection not raising SelectionChanged.

pull/3470/head
Steven Kirk 6 years ago
parent
commit
e3d11a8288
  1. 2
      src/Avalonia.Controls/SelectionModel.cs
  2. 23
      src/Avalonia.Controls/SelectionNode.cs

2
src/Avalonia.Controls/SelectionModel.cs

@ -324,6 +324,7 @@ namespace Avalonia.Controls
public void Dispose()
{
ClearSelection(resetAnchor: false);
_rootNode.Cleanup();
_rootNode.Dispose();
_selectedIndicesCached = null;
_selectedItemsCached = null;
@ -764,6 +765,7 @@ namespace Avalonia.Controls
}
OnSelectionChanged(e);
_rootNode.Cleanup();
}
internal class SelectedItemInfo : ISelectedItemInfo

23
src/Avalonia.Controls/SelectionNode.cs

@ -342,6 +342,19 @@ namespace Avalonia.Controls
}
}
public void Cleanup()
{
foreach (var child in _childrenNodes)
{
child?.Cleanup();
if (child?.SelectedCount == 0)
{
child.Dispose();
}
}
}
public bool Select(int index, bool select)
{
return Select(index, select, raiseOnSelectionChanged: true);
@ -453,16 +466,6 @@ namespace Avalonia.Controls
SelectedCount = 0;
AnchorIndex = -1;
// This will throw away all the children SelectionNodes
// causing them to be unhooked from their data source. This
// essentially cleans up the tree.
foreach (var child in _childrenNodes)
{
child?.Dispose();
}
_childrenNodes.Clear();
}
private bool Select(int index, bool select, bool raiseOnSelectionChanged)

Loading…
Cancel
Save