Browse Source

add fix for selecting items control.

Dan Walmsley 7 years ago
parent
commit
ae4356ef34
1 changed files with 6 additions and 0 deletions
  1. 6 0
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

+ 6 - 0
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@@ -355,6 +355,12 @@ namespace Avalonia.Controls.Primitives
                 case NotifyCollectionChangedAction.Replace:
                     var selectedIndex = SelectedIndex;
 
+                    var items = Items?.Cast<object>();
+                    if (selectedIndex >= items.Count())
+                    {
+                        selectedIndex = SelectedIndex = items.Count() - 1;
+                    }
+
                     if (selectedIndex >= e.OldStartingIndex &&
                         selectedIndex < e.OldStartingIndex + e.OldItems.Count)
                     {