private void RemoveItem(int index) { if (index < InternalChildren.Count) { RemoveInternalChildRange(index, 1); } else { int indexInOverflowPanel = index - InternalChildren.Count; if (QAT != null && QAT.OverflowPanel != null) { QAT.OverflowPanel.Children.RemoveAt(indexInOverflowPanel); } } GeneratedChildren.RemoveAt(index); }
protected override void OnItemsChanged(object sender, ItemsChangedEventArgs args) { base.OnItemsChanged(sender, args); switch (args.Action) { case NotifyCollectionChangedAction.Add: if (Generator != null) { using (Generator.StartAt(args.Position, GeneratorDirection.Forward, true)) { UIElement childToAdd = Generator.GenerateNext() as UIElement; Generator.PrepareItemContainer(childToAdd); int indexToInsertAt = Generator.IndexFromGeneratorPosition(args.Position); GeneratedChildren.Insert(indexToInsertAt, childToAdd); } } break; case NotifyCollectionChangedAction.Remove: RemoveItem(args.Position.Index); break; case NotifyCollectionChangedAction.Reset: RemoveInternalChildRange(0, InternalChildren.Count); if (QAT != null && QAT.OverflowPanel != null) { QAT.OverflowPanel.Children.Clear(); } RepopulateGeneratedChildren(); break; case NotifyCollectionChangedAction.Move: UIElement childToMove = GeneratedChildren[args.OldPosition.Index]; RemoveItem(args.OldPosition.Index); GeneratedChildren.Insert(args.Position.Index, childToMove); break; case NotifyCollectionChangedAction.Replace: break; } }