private void MoveChildren(GeneratorPosition fromPos, GeneratorPosition toPos, int containerCount) { if (fromPos == toPos) return; Debug.Assert(_itemContainerGenerator != null, "Encountered a null _itemContainerGenerator while receiving an Move action from a generator."); IItemContainerGenerator generator = (IItemContainerGenerator)_itemContainerGenerator; int toIndex = generator.IndexFromGeneratorPosition(toPos); UIElement[] elements = new UIElement[containerCount]; for (int i = 0; i < containerCount; i++) elements[i] = _uiElementCollection[fromPos.Index + i]; _uiElementCollection.RemoveRangeInternal(fromPos.Index, containerCount); for (int i = 0; i < containerCount; i++) { _uiElementCollection.InsertInternal(toIndex + i, elements[i]); } }
// This is internal as an optimization for VirtualizingStackPanel (so it doesn't need to re-query InternalChildren repeatedly) internal static void RemoveInternalChildRange(UIElementCollection children, int index, int range) { children.RemoveRangeInternal(index, range); }