internal IDisposable StartAt (GeneratorPosition position, GeneratorDirection direction, bool allowStartAtRealizedItem) { if (GenerationState != null) throw new InvalidOperationException ("Cannot call StartAt while a generation operation is in progress"); GenerationState = new GenerationState { AllowStartAtRealizedItem = allowStartAtRealizedItem, Direction = direction, Position = position, Generator = this }; return GenerationState; }
void AddItemsToPresenter(GeneratorPosition position, int count) { if (_presenter == null || _presenter._elementRoot == null || _presenter._elementRoot is VirtualizingPanel) { return; } Panel panel = _presenter._elementRoot; int newIndex = ItemContainerGenerator.IndexFromGeneratorPosition(position); using (var p = ItemContainerGenerator.StartAt(position, GeneratorDirection.Forward, true)) for (int i = 0; i < count; i++) { var item = Items [newIndex + i]; DependencyObject container = null; bool fresh; container = ItemContainerGenerator.GenerateNext(out fresh); ContentControl c = container as ContentControl; if (c != null) { c.ContentSetsParent = false; } FrameworkElement f = container as FrameworkElement; if (f != null && !(item is FrameworkElement)) { f.DataContext = item; } panel.Children.Insert(newIndex + i, (UIElement)container); ItemContainerGenerator.PrepareItemContainer(container); } }