Skip to content

Commit

Permalink
fix(listviewbase): calling UpdateLayout during reordering breaks the …
Browse files Browse the repository at this point in the history
…ListView
  • Loading branch information
ramezgerges committed Jun 4, 2024
1 parent 81e55a4 commit a8f41f1
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private protected VirtualizingPanelGenerator Generator
private Size _availableSize;
private Size _lastMeasuredSize;
private double _lastScrollOffset;
private bool _clearingLines;

/// <summary>
/// The current average line height based on materialized lines. Used to estimate scroll extent of unmaterialized items.
Expand Down Expand Up @@ -347,6 +348,10 @@ private double GetScrollConsumptionIncrement(GeneratorDirection fillDirection)

internal Size MeasureOverride(Size availableSize)
{
if (_clearingLines)
{
return new Size(0, 0);
}
if (ItemsControl == null)
{
if (this.Log().IsEnabled(LogLevel.Debug))
Expand Down Expand Up @@ -830,11 +835,24 @@ private void ClearLines(bool clearContainer)
this.Log().LogDebug($"{GetMethodTag()}");
}

foreach (var line in _materializedLines)
_clearingLines = true;
try
{
RecycleLine(line, clearContainer);
// Recycling a line can lead to removing elements from the visual tree.
// If a user forces a layout during this (e.g. in Unloaded), we will
// update the _materializedLines in MeasureOverride. So, to prevent
// modification while looping, we take a copy and clear before looping.
var lines = _materializedLines.ToList();
_materializedLines.Clear();
foreach (var line in lines)
{
RecycleLine(line, clearContainer);
}
}
finally
{
_clearingLines = false;
}
_materializedLines.Clear();
}

/// <summary>
Expand Down

0 comments on commit a8f41f1

Please sign in to comment.