private void AddChildren(GeneratorPosition pos, int itemCount) { Debug.Assert(_itemContainerGenerator != null, "Encountered a null _itemContainerGenerator while receiving an Add action from a generator."); IItemContainerGenerator generator = (IItemContainerGenerator)_itemContainerGenerator; using (generator.StartAt(pos, GeneratorDirection.Forward)) { for (int i = 0; i < itemCount; i++) { UIElement e = generator.GenerateNext() as UIElement; if(e != null) { _uiElementCollection.InsertInternal(pos.Index + 1 + i, e); generator.PrepareItemContainer(e); } else { _itemContainerGenerator.Verify(); } } } }
// This is internal as an optimization for VirtualizingStackPanel (so it doesn't need to re-query InternalChildren repeatedly) internal static void InsertInternalChild(UIElementCollection children, int index, UIElement child) { children.InsertInternal(index, child); }