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(); } } } }