Browse Source

Throw not implemented exception placeholder.

danwalmsley 9 years ago
parent
commit
2e9c19beaf
1 changed files with 26 additions and 6 deletions
  1. 26 6
      src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs

+ 26 - 6
src/Avalonia.Controls/Presenters/ItemVirtualizerSimple.cs

@@ -42,7 +42,7 @@ namespace Avalonia.Controls.Presenters
                         if (panel.PixelOffset > 0)
                         {
                             panel.PixelOffset = 0;
-                            delta += 1;                           
+                            delta += 1;
                         }
 
                         if (delta != 0)
@@ -87,6 +87,18 @@ namespace Avalonia.Controls.Presenters
 
             switch (e.Action)
             {
+                case NotifyCollectionChangedAction.Remove:
+                    if (e.OldStartingIndex == ItemCount)
+                    {
+                        NextIndex = ItemCount - 1;
+
+                        throw new NotImplementedException("Remove the last item from the panel.");
+                    }
+
+                    CreateRemoveContainers();
+                    RecycleContainers();
+                    break;
+
                 case NotifyCollectionChangedAction.Add:
                     if (e.NewStartingIndex >= FirstIndex &&
                         e.NewStartingIndex + e.NewItems.Count < NextIndex)
@@ -183,17 +195,25 @@ namespace Avalonia.Controls.Presenters
 
             foreach (var container in containers)
             {
-                var item = Items.ElementAt(itemIndex);
-
-                if (!object.Equals(container.Item, item))
+                if (itemIndex < ItemCount)
                 {
-                    if (!generator.TryRecycle(itemIndex, itemIndex, item, selector))
+                    var item = Items.ElementAt(itemIndex);
+
+                    if (!object.Equals(container.Item, item))
                     {
-                        throw new NotImplementedException();
+                        if (!generator.TryRecycle(itemIndex, itemIndex, item, selector))
+                        {
+                            throw new NotImplementedException();
+                        }
                     }
                 }
+                else
+                {
+                    panel.Children.RemoveAt(panel.Children.Count - 1);
+                }
 
                 ++itemIndex;
+
             }
         }