Browse Source

Extend the fix for Recycling the focused element to non virtualized l…

…ayouts

* Ensure that we set the m_processingItesmSourceChange flag for non-virtualizing layouts as well as virtualizing ones.

Ported from https://github.com/microsoft/microsoft-ui-xaml/commit/cc335ac3915ed37ac7ee95237b789622287d2f5a
Steven Kirk 5 years ago
parent
commit
bb7276d568
1 changed files with 18 additions and 18 deletions
  1. 18 18
      src/Avalonia.Controls/Repeater/ItemsRepeater.cs

+ 18 - 18
src/Avalonia.Controls/Repeater/ItemsRepeater.cs

@@ -562,34 +562,34 @@ namespace Avalonia.Controls
 
             if (Layout != null)
             {
-                if (Layout is VirtualizingLayout virtualLayout)
-                {
-                    var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
+                var args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
 
+                try
+                {
                     _processingItemsSourceChange = args;
 
-                    try
+                    if (Layout is VirtualizingLayout virtualLayout)
                     {
                         virtualLayout.OnItemsChanged(GetLayoutContext(), newValue, args);
                     }
-                    finally
+                    else if (Layout is NonVirtualizingLayout nonVirtualLayout)
                     {
-                        _processingItemsSourceChange = null;
-                    }
-                }
-                else if (Layout is NonVirtualizingLayout nonVirtualLayout)
-                {
-                    // Walk through all the elements and make sure they are cleared for
-                    // non-virtualizing layouts.
-                    foreach (var element in Children)
-                    {
-                        if (GetVirtualizationInfo(element).IsRealized)
+                        // Walk through all the elements and make sure they are cleared for
+                        // non-virtualizing layouts.
+                        foreach (var element in Children)
                         {
-                            ClearElementImpl(element);
+                            if (GetVirtualizationInfo(element).IsRealized)
+                            {
+                                ClearElementImpl(element);
+                            }
                         }
-                    }
 
-                    Children.Clear();
+                        Children.Clear();
+                    }
+                }
+                finally
+                {
+                    _processingItemsSourceChange = null;
                 }
 
                 InvalidateMeasure();