IndexFromGeneratorPosition() public method

public IndexFromGeneratorPosition ( GeneratorPosition position ) : int
position GeneratorPosition
return int
Exemplo n.º 1
0
        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);
                }
        }