コード例 #1
0
		internal ItemsChangedEventArgs (NotifyCollectionChangedAction action, int itemCount, int itemUICount, GeneratorPosition oldPosition, GeneratorPosition position)
		{
			this.action = action;
			item_count = itemCount;
			item_ui_count = itemUICount;
			old_position = oldPosition;
			this.position = position;
		}
コード例 #2
0
 private void CleanUpItems(int firstIndex, int lastIndex)
 {
     for (int i = InternalChildren.Count - 1; i >= 0; i--)
     {
         var childGeneratorPos = new GeneratorPosition(i, 0);
         int itemIndex         = generator.IndexFromGeneratorPosition(childGeneratorPos);
         if ((itemIndex < firstIndex || itemIndex > lastIndex) && itemIndex > 0)
         {
             generator.Remove(childGeneratorPos, 1);
             RemoveInternalChildRange(i, 1);
         }
     }
 }
コード例 #3
0
        internal void Recycle(GeneratorPosition position, int count)
        {
            this.CheckOffsetAndRealized(position, count);

            int index = this.IndexFromGeneratorPosition(position);

            for (int i = 0; i < count; i++)
            {
                this.Cache.Enqueue(this.ContainerIndexMap[index + i]);
            }

            this.Remove(position, count);
        }
コード例 #4
0
 public void CleanUpItems(int minDesiredGenerated, int maxDesiredGenerated)
 {
     for (int i = this._children.Count - 1; i >= 0; i--)
     {
         GeneratorPosition childGeneratorPos = new GeneratorPosition(i, 0);
         int itemIndex = this._generator.IndexFromGeneratorPosition(childGeneratorPos);
         if (itemIndex < minDesiredGenerated || itemIndex > maxDesiredGenerated)
         {
             this._generator.Remove(childGeneratorPos, 1);
             this.RemoveInternalChildRange(i, 1);
         }
     }
 }
コード例 #5
0
 /// <summary>
 /// Removes items that are outside the desired positions</summary>
 /// <param name="minDesiredGenerated">Minimum desired generator position</param>
 /// <param name="maxDesiredGenerated">Maximum desired generator position</param>
 protected void CleanUpItems(int minDesiredGenerated, int maxDesiredGenerated)
 {
     for (int i = m_children.Count - 1; i >= 0; i--)
     {
         var childGeneratorPos = new GeneratorPosition(i, 0);
         int itemIndex         = m_generator.IndexFromGeneratorPosition(childGeneratorPos);
         if (itemIndex < minDesiredGenerated || itemIndex > maxDesiredGenerated)
         {
             m_generator.Remove(childGeneratorPos, 1);
             RemoveInternalChildRange(i, 1);
         }
     }
 }
コード例 #6
0
 /// <summary>
 /// Revirtualizes the items that are no longer visible.
 /// </summary>
 /// <param name="minDesiredGenerated">The first item index that should be visible.</param>
 /// <param name="maxDesiredGenerated">The last item index that should be visible.</param>
 private void CleanUpItems(int minDesiredGenerated, int maxDesiredGenerated)
 {
     for (int i = InternalChildren.Count - 1; i >= 0; i--)
     {
         GeneratorPosition childPos = new GeneratorPosition(i, 0);
         int itemIndex = ItemContainerGenerator.IndexFromGeneratorPosition(childPos);
         if (itemIndex < minDesiredGenerated || itemIndex > maxDesiredGenerated)
         {
             ItemContainerGenerator.Remove(childPos, 1);
             RemoveInternalChildRange(i, 1);
         }
     }
 }
コード例 #7
0
        void GenerateItemContainers()
        {
            IItemContainerGenerator generator = ItemContainerGenerator;
            GeneratorPosition       position  = generator.GeneratorPositionFromIndex(0);

            using (generator.StartAt(position, GeneratorDirection.Forward, true))
            {
                foreach (object o in Items)
                {
                    DependencyObject dp = generator.GenerateNext();
                    generator.PrepareItemContainer(dp);
                }
            }
        }
コード例 #8
0
        void RemoveItemsFromPresenter(GeneratorPosition position, int count)
        {
            if (_presenter == null || _presenter._elementRoot == null || _presenter._elementRoot is VirtualizingPanel)
            {
                return;
            }

            Panel panel = _presenter._elementRoot;

            while (count-- > 0)
            {
                panel.Children.RemoveAt(position.Index);
            }
        }
コード例 #9
0
        public void GeneratorPositionFromIndex_OutOfRange_TwoElements_Realised()
        {
            Control.Items.Add(new object());
            Control.Items.Add(new object());

            CreateAsyncTest(Control,
                            () => Control.ApplyTemplate(),
                            () => {
                GeneratorPosition p = Generator.GeneratorPositionFromIndex(100);
                Assert.AreEqual(-1, p.Index, "#1");
                Assert.AreEqual(0, p.Offset, "#2");
            }
                            );
        }
コード例 #10
0
        private void RealizeFirstItem()
        {
            IItemContainerGenerator generator = ItemContainerGenerator;
            GeneratorPosition       pos       = generator.GeneratorPositionFromIndex(0);

            using (generator.StartAt(pos, GeneratorDirection.Forward))
            {
                var element = generator.GenerateNext() as UIElement;

                generator.PrepareItemContainer(element);

                AddInternalChild(element);
            }
        }
コード例 #11
0
ファイル: Window1.xaml.cs プロジェクト: zhimaqiao51/docs
        void GenerateForwardFromMiddle()
        {
            //<SnippetGenerateForwardFromMiddleCODE>
            // Start generating items forward,
            // starting with the first unrealized item (offset of 1),
            // after the 5th realized item
            // (the item with index 4 among all realized items) in the list
            GeneratorPosition       position  = new GeneratorPosition(4, 1);
            GeneratorDirection      direction = GeneratorDirection.Forward;
            IItemContainerGenerator generator = (IItemContainerGenerator)this.itemsControl.ItemContainerGenerator;

            generator.StartAt(position, direction);
            //</SnippetGenerateForwardFromMiddleCODE>
        }
コード例 #12
0
        private void MeasureCore()
        {
            // 注意,在第一次使用 ItemContainerGenerator之前要先访问一下InternalChildren,
            // 否则ItemContainerGenerator为null,是一个Bug
            UIElementCollection     children  = InternalChildren;
            IItemContainerGenerator generator = ItemContainerGenerator;

            if (generator != null)
            {
                // 获取第一个可视元素位置信息
                GeneratorPosition position = generator.GeneratorPositionFromIndex(this._startIndex);
                // 根据元素位置信息计算子元素索引
                int childIndex = position.Offset == 0 ? position.Index : position.Index + 1;

                using (generator.StartAt(position, GeneratorDirection.Forward, true))
                {
                    for (int itemIndex = this._startIndex; itemIndex <= this._endIndex; itemIndex++, childIndex++)
                    {
                        bool isNewlyRealized;                           // 用以指示新生成的元素是否是新实体化的

                        // 生成下一个子元素
                        var child = (UIElement)generator.GenerateNext(out isNewlyRealized);

                        if (child == null)
                        {
                            break;
                        }

                        if (isNewlyRealized)
                        {
                            if (childIndex >= children.Count)
                            {
                                AddInternalChild(child);
                            }
                            else
                            {
                                InsertInternalChild(childIndex, child);
                            }
                            generator.PrepareItemContainer(child);
                        }

                        // 测算子元素布局
                        child.Measure(this._eachSize);
                    }
                }
            }

            this.CleanUpItems(this._startIndex, this._endIndex);
        }
コード例 #13
0
        /// <summary>
        /// scroll/availableSize/添加删除元素 改变都会触发  edit元素不会改变
        /// </summary>
        /// <param name="availableSize"></param>
        /// <returns></returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            this.UpdateScrollInfo(availableSize);//availableSize更新后,更新滚动条
            int firstVisiableIndex = 0, lastVisiableIndex = 0;

            GetVisiableRange(ref firstVisiableIndex, ref lastVisiableIndex); //availableSize更新后,获取当前viewport内可放置的item的开始和结束索引  firstIdnex-lastIndex之间的item可能部分在viewport中也可能都不在viewport中。

            UIElementCollection     children  = this.InternalChildren;       //因为配置了虚拟化,所以children的个数一直是viewport区域内的个数,如果没有虚拟化则是ItemSource的整个的个数
            IItemContainerGenerator generator = this.ItemContainerGenerator;
            //获得第一个可被显示的item的位置
            GeneratorPosition startPosi = generator.GeneratorPositionFromIndex(firstVisiableIndex);
            int childIndex = (startPosi.Offset == 0) ? startPosi.Index : startPosi.Index + 1;//startPosi在chilren中的索引

            using (generator.StartAt(startPosi, GeneratorDirection.Forward, true))
            {
                int itemIndex = firstVisiableIndex;
                while (itemIndex <= lastVisiableIndex)//生成lastVisiableIndex-firstVisiableIndex个item
                {
                    bool newlyRealized = false;
                    var  child         = generator.GenerateNext(out newlyRealized) as UIElement;
                    if (newlyRealized)
                    {
                        if (childIndex >= children.Count)
                        {
                            base.AddInternalChild(child);
                        }
                        else
                        {
                            base.InsertInternalChild(childIndex, child);
                        }
                        generator.PrepareItemContainer(child);
                    }
                    else
                    {
                        //处理 正在显示的child被移除了这种情况
                        if (!child.Equals(children[childIndex]))
                        {
                            base.RemoveInternalChildRange(childIndex, 1);
                        }
                    }
                    child.Measure(new Size(this.ChildWidth, this.ChildHeight));
                    //child.DesiredSize//child想要的size
                    itemIndex++;
                    childIndex++;
                }
            }
            CleanUpItems(firstVisiableIndex, lastVisiableIndex);
            return(new Size(double.IsInfinity(availableSize.Width) ? 0 : availableSize.Width, double.IsInfinity(availableSize.Height) ? 0 : availableSize.Height));//自身想要的size
        }
コード例 #14
0
        public void VirtualizeItem(int itemIndex)
        {
            IItemContainerGenerator itemContainerGenerator = base.ItemContainerGenerator;

            if (itemContainerGenerator != null)
            {
                GeneratorPosition position = itemContainerGenerator.GeneratorPositionFromIndex(itemIndex);
                if (position.Offset == 0)
                {
                    itemContainerGenerator.Remove(position, 1);
                    base.InternalChildren[position.Index].ClearValue(IndexForItemContainerProperty);
                    RemoveInternalChildRange(position.Index, 1);
                }
            }
        }
コード例 #15
0
        public void CleanUp(int minDesiredGenerated, int maxDesiredGenerated)
        {
            int internalChildrenCount = _panel.getInternalChildren().Count;

            for (int i = internalChildrenCount - 1; i >= 0; i--)
            {
                GeneratorPosition childGeneratorPos = new GeneratorPosition(i, 0);
                int itemIndex = _generator.IndexFromGeneratorPosition(childGeneratorPos);
                if (itemIndex < minDesiredGenerated || itemIndex > maxDesiredGenerated)
                {
                    _generator.Remove(childGeneratorPos, 1);
                    _panel.removeInternalChild(i);
                }
            }
        }
コード例 #16
0
        private void CleanupItems()
        {
            IItemContainerGenerator generator = _itemsOwner.ItemContainerGenerator;

            for (int i = InternalChildren.Count - 1; i >= 0; i--)
            {
                var position  = new GeneratorPosition(i, 0);
                int itemIndex = generator.IndexFromGeneratorPosition(position);
                if (itemIndex < _startIndex || itemIndex > _endIndex)
                {
                    generator.Remove(position, 1);
                    RemoveInternalChildRange(i, 1);
                }
            }
        }
コード例 #17
0
        private UIElement ForceContainerGeneration(object item)
        {
            int       itemIndex               = IndexOf(item);
            UIElement container               = null;
            bool      isNewlyRealized         = false;
            IItemContainerGenerator generator = dataGrid.ItemContainerGenerator;
            GeneratorPosition       gp        = generator.GeneratorPositionFromIndex(itemIndex);

            using (generator.StartAt(gp, GeneratorDirection.Forward, true))
            {
                isNewlyRealized = false;
                container       = generator.GenerateNext(out isNewlyRealized) as UIElement;
            }
            return(container);
        }
コード例 #18
0
        private void CleanUpChildren(int minIndex, int maxIndex)
        {
            UIElementCollection     children  = base.Children;
            IItemContainerGenerator generator = base.ItemContainerGenerator;

            for (int i = children.Count - 1; i >= 0; i--)
            {
                GeneratorPosition pos = new GeneratorPosition(i, 0);
                int itemIndex         = generator.IndexFromGeneratorPosition(pos);
                if (itemIndex < minIndex || itemIndex > maxIndex)
                {
                    generator.Remove(pos, 1);
                    base.RemoveInternalChildRange(i, 1);
                }
            }
        }
コード例 #19
0
        private void CleanUpChildren(int minIndex, int maxIndex)
        {
            var children  = this.Children;
            var generator = this.ItemContainerGenerator;

            for (var i = children.Count - 1; i >= 0; i--)
            {
                var pos       = new GeneratorPosition(i, 0);
                var itemIndex = generator.IndexFromGeneratorPosition(pos);
                if (itemIndex < minIndex || itemIndex > maxIndex)
                {
                    generator.Remove(pos, 1);
                    RemoveInternalChildRange(i, 1);
                }
            }
        }
コード例 #20
0
        void CheckOffsetAndRealized(GeneratorPosition position, int count)
        {
            if (position.Offset != 0)
            {
                throw new ArgumentException("position.Offset must be zero as the position must refer to a realized element");
            }

            int index      = IndexFromGeneratorPosition(position);
            int rangeIndex = RealizedElements.FindRangeIndexForValue(index);

            RangeCollection.Range range = RealizedElements.Ranges[rangeIndex];
            if (index < range.Start || (index + count) > range.Start + range.Count)
            {
                throw new InvalidOperationException("Only items which have been Realized can be removed");
            }
        }
コード例 #21
0
        internal void Remove(GeneratorPosition position, int count)
        {
            this.CheckOffsetAndRealized(position, count);

            int index = this.IndexFromGeneratorPosition(position);

            for (int i = 0; i < count; i++)
            {
                var container = this.ContainerIndexMap[index + i];
                var item      = this.ContainerItemMap[container];
                this.ContainerIndexMap.Remove(container, index + i);
                this.ContainerItemMap.Remove(container);
                this.RealizedElements.Remove(index + i);
                this.Owner.ClearContainerForItem(container, item);
            }
        }
コード例 #22
0
ファイル: App.xaml.cs プロジェクト: MadEste/PackageChanges
 void TestAnalyzers()
 {
     PropertyChangedEventArgs      changeArgs = new PropertyChangedEventArgs("tstProp");
     ObservableCollection <string> c          = new ObservableCollection <string>(); //Cannot run in try-convert
     var cornerRadius1     = new CornerRadius(2);
     var cornerRadius2     = new CornerRadius(1, 2, 3, 4);
     var duration          = new Duration(new TimeSpan(33));
     var gridLength1       = new GridLength(12);
     var gridLength2       = new GridLength(1, GridUnitType.Pixel);
     var thickness1        = new Thickness(2);
     var thickness2        = new Thickness(2, 3, 4, 5);
     var generatorPosition = new GeneratorPosition(23, 123);
     var matrix            = new Matrix(6, 5, 4, 3, 2, 1);
     var repeatBehavior1   = new RepeatBehavior(12);
     var repeatBehavior2   = new RepeatBehavior(new TimeSpan(10));
 }
コード例 #23
0
        private void CleanUpItems(int minDesiredGenerated, int maxDesiredGenerated)
        {
            UIElementCollection     internalChildren       = base.InternalChildren;
            IItemContainerGenerator itemContainerGenerator = base.ItemContainerGenerator;

            for (int i = internalChildren.Count - 1; i >= 0; i--)
            {
                GeneratorPosition position = new GeneratorPosition(i, 0);
                int num2 = itemContainerGenerator.IndexFromGeneratorPosition(position);
                if ((num2 < minDesiredGenerated) || (num2 > maxDesiredGenerated))
                {
                    itemContainerGenerator.Remove(position, 1);
                    base.RemoveInternalChildRange(i, 1);
                }
            }
        }
コード例 #24
0
        /// <summary>
        ///     Revirtualize items that are no longer visible
        /// </summary>
        /// <param name="minDesiredGenerated">first item index that should be visible</param>
        /// <param name="maxDesiredGenerated">last item index that should be visible</param>
        private void CleanUpItems(int minDesiredGenerated, int maxDesiredGenerated)
        {
            var children  = InternalChildren;
            var generator = ItemContainerGenerator;

            for (var i = children.Count - 1; i >= 0; i--)
            {
                var childGeneratorPos = new GeneratorPosition(i, 0);
                var itemIndex         = generator.IndexFromGeneratorPosition(childGeneratorPos);
                if (itemIndex < minDesiredGenerated || itemIndex > maxDesiredGenerated)
                {
                    generator.Remove(childGeneratorPos, 1);
                    RemoveInternalChildRange(i, 1);
                }
            }
        }
コード例 #25
0
        private void RemoveItemsFromPresenter(GeneratorPosition position, int count)
        {
            if (this.itemsPresenter == null ||
                this.itemsPresenter.Child == null ||
                this.itemsPresenter.Child is VirtualizingPanel)
            {
                return;
            }

            Panel panel = this.itemsPresenter.Child;

            while (count-- > 0)
            {
                panel.InternalChildren.RemoveAt(position.Index);
            }
        }
コード例 #26
0
        /// <summary>
        /// Revirtualize items that are no longer visible
        /// </summary>
        /// <param name="minDesiredGenerated">first item index that should be visible</param>
        /// <param name="maxDesiredGenerated">last item index that should be visible</param>
        private void CleanUpItems(int minDesiredGenerated, int maxDesiredGenerated)
        {
            UIElementCollection     children  = this.InternalChildren;
            IItemContainerGenerator generator = this.ItemContainerGenerator;

            for (int i = children.Count - 1; i >= 0; i--)
            {
                GeneratorPosition childGeneratorPos = new GeneratorPosition(i, 0);
                int itemIndex = generator.IndexFromGeneratorPosition(childGeneratorPos);
                if (itemIndex < minDesiredGenerated || itemIndex > maxDesiredGenerated)
                {
                    generator.Remove(childGeneratorPos, 1);
                    RemoveInternalChildRange(i, 1);
                }
            }
        }
コード例 #27
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var       value1                  = dg.ItemContainerGenerator.ContainerFromIndex(30);
            UIElement cntr                    = null;
            bool      isNewlyRealized         = false;
            IItemContainerGenerator generator = dg.ItemContainerGenerator;
            GeneratorPosition       gp        = generator.GeneratorPositionFromIndex(30);

            using (generator.StartAt(gp, GeneratorDirection.Forward, true))
            {
                isNewlyRealized = false;
                cntr            = generator.GenerateNext(out isNewlyRealized) as UIElement;
            }

            MessageBox.Show("Row 30: " + value1 + ", " + cntr + ", " + isNewlyRealized);
        }
コード例 #28
0
 private void CleanUpItems(int minDesiredGenerated, int maxDesiredGenerated)
 {
     for (var i = _children.Count - 1; i >= 0; i--)
     {
         var childGeneratorPos = new GeneratorPosition(i, 0);
         var itemIndex         = _generator.IndexFromGeneratorPosition(childGeneratorPos);
         if (itemIndex < minDesiredGenerated || itemIndex > maxDesiredGenerated)
         {
             if (itemIndex >= 0)
             {
                 _generator.Remove(childGeneratorPos, 1);
             }
             RemoveInternalChildRange(i, 1);
         }
     }
 }
コード例 #29
0
        /// <summary>
        /// <see cref="System.Windows.Media.Visual"/> オブジェクトの座標空間が表示されるまで、
        /// コンテンツを強制的にスクロールする。
        /// </summary>
        /// <param name="visual">表示可能になる <see cref="System.Windows.Media.Visual"/>。</param>
        /// <param name="rectangle">表示する座標空間を識別する外接する四角形。</param>
        /// <returns>表示される <see cref="System.Windows.Rect"/>。</returns>
        public Rect MakeVisible(Visual visual, Rect rectangle)
        {
            var idx = this.InternalChildren.IndexOf(visual as UIElement);

            var generator = this.ItemContainerGenerator as IItemContainerGenerator;

            if (generator != null)
            {
                var pos = new GeneratorPosition(idx, 0);
                idx = generator.IndexFromGeneratorPosition(pos);
            }

            if (idx < 0)
            {
                return(Rect.Empty);
            }

            if (!this.containerLayouts.ContainsKey(idx))
            {
                return(Rect.Empty);
            }

            var layout = this.containerLayouts[idx];

            if (this.HorizontalOffset + this.ViewportWidth < layout.X + layout.Width)
            {
                this.SetHorizontalOffset(layout.X + layout.Width - this.ViewportWidth);
            }
            if (layout.X < this.HorizontalOffset)
            {
                this.SetHorizontalOffset(layout.X);
            }

            if (this.VerticalOffset + this.ViewportHeight < layout.Y + layout.Height)
            {
                this.SetVerticalOffset(layout.Y + layout.Height - this.ViewportHeight);
            }
            if (layout.Y < this.VerticalOffset)
            {
                this.SetVerticalOffset(layout.Y);
            }

            layout.Width  = Math.Min(this.ViewportWidth, layout.Width);
            layout.Height = Math.Min(this.ViewportHeight, layout.Height);

            return(layout);
        }
コード例 #30
0
ファイル: TreeGridCellsPanel.cs プロジェクト: yungtau/oea
        /// <summary>
        /// 清除不显示的单元格。
        /// </summary>
        /// <param name="children"></param>
        /// <param name="generator"></param>
        private void Cleanup(UIElementCollection children, IItemContainerGenerator generator)
        {
            //清除不需要显示的子元素,注意从集合后向前操作,以免造成操作过程中元素索引发生改变
            for (int i = children.Count - 1; i > -1; i--)
            {
                // 通过已显示的子元素的位置信息得出元素索引
                var childGeneratorPos = new GeneratorPosition(i, 0);
                int itemIndex         = generator.IndexFromGeneratorPosition(childGeneratorPos);

                // 移除不再显示的元素
                if (itemIndex < this._from || itemIndex > this._to)
                {
                    generator.Remove(childGeneratorPos, 1);
                    this.RemoveInternalChildRange(i, 1);
                }
            }
        }
コード例 #31
0
        private void CleanUpItems(int minDesiredGenerated, int maxDesiredGenerated)
        {
            var internalChildren       = InternalChildren;
            var itemContainerGenerator = ItemContainerGenerator;

            for (var i = internalChildren.Count - 1; i >= 0; i--)
            {
                var position = new GeneratorPosition(i, 0);
                var num2     = itemContainerGenerator.IndexFromGeneratorPosition(position);
                if ((num2 >= minDesiredGenerated) && (num2 <= maxDesiredGenerated))
                {
                    continue;
                }
                itemContainerGenerator.Remove(position, 1);
                RemoveInternalChildRange(i, 1);
            }
        }
コード例 #32
0
		void IItemContainerGenerator.Remove (GeneratorPosition position, int count)
		{
			throw new Exception ("The method or operation is not implemented.");
		}
コード例 #33
0
		int IItemContainerGenerator.IndexFromGeneratorPosition (GeneratorPosition position)
		{
			throw new Exception ("The method or operation is not implemented.");
		}
コード例 #34
0
		IDisposable IItemContainerGenerator.StartAt (GeneratorPosition position, GeneratorDirection direction, bool allowStartAtRealizedItem)
		{
			throw new Exception ("The method or operation is not implemented.");
		}