当前位置: 首页>>代码示例>>C#>>正文


C# Primitives.GeneratorPosition类代码示例

本文整理汇总了C#中System.Windows.Controls.Primitives.GeneratorPosition的典型用法代码示例。如果您正苦于以下问题:C# GeneratorPosition类的具体用法?C# GeneratorPosition怎么用?C# GeneratorPosition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GeneratorPosition类属于System.Windows.Controls.Primitives命名空间,在下文中一共展示了GeneratorPosition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ItemsChangedEventArgs

 internal ItemsChangedEventArgs(NotifyCollectionChangedAction action,
                                 GeneratorPosition position,
                                 int itemCount,
                                 int itemUICount) : this(action, position, new GeneratorPosition(-1, 0), itemCount, itemUICount)
          
 {
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:7,代码来源:ItemsChangedEventArgs.cs

示例2: CustomGeneratorChangedEventArgs

 internal CustomGeneratorChangedEventArgs( NotifyCollectionChangedAction action, GeneratorPosition position, int index, GeneratorPosition oldPosition, int oldIndex, int itemCount, int itemUICount, IList<DependencyObject> removedContainers )
 {
   _action = action;
   _position = position;
   _oldPosition = oldPosition;
   _itemCount = itemCount;
   _itemUICount = itemUICount;
   _index = index;
   _oldIndex = oldIndex;
   m_removedContainers = removedContainers;
 }
开发者ID:austinedeveloper,项目名称:WpfExtendedToolkit,代码行数:11,代码来源:CustomGeneratorChangedEventArgs.cs

示例3: CleanUpItems

		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);
			}
		}
开发者ID:CyberFoxHax,项目名称:PCSXBonus,代码行数:11,代码来源:VirtualizingTilePanel.cs

示例4: MeasureOverride

        protected override Size MeasureOverride(Size availableSize)
        {
            var desiredSize = new Size();
            ItemsControl parent = ItemsControl.GetItemsOwner(this);
            int count = parent != null && parent.HasItems ? parent.Items.Count : 0;

            // Next line needed otherwise ItemContainerGenerator is null (bug in WinFX ?)
            UIElementCollection children = InternalChildren;
            IItemContainerGenerator generator = ItemContainerGenerator;

            if (count == 0)
            {
                generator.RemoveAll();
                if (children.Count > 0) RemoveInternalChildRange(0, children.Count);
                return desiredSize;
            }

            // Get the generator position of the first visible data item
            GeneratorPosition startPos = generator.GeneratorPositionFromIndex(count - 1);
            using (generator.StartAt(startPos, GeneratorDirection.Forward, true))
            {
                bool newlyRealized;
                // Get or create the child
                var child = generator.GenerateNext(out newlyRealized) as UIElement;

                if (child != null)
                {
                    if (newlyRealized)
                    {
                        AddInternalChild(child);
                        generator.PrepareItemContainer(child);
                    }
                    child.Measure(availableSize);
                    desiredSize = child.DesiredSize;
                }
            }

            // Remove all other items than the top one
            for (int i = children.Count - 1; i >= 0; i--)
            {
                var childGeneratorPos = new GeneratorPosition(i, 0);
                int itemIndex = generator.IndexFromGeneratorPosition(childGeneratorPos);
                if (itemIndex == count - 1) continue;
                generator.Remove(childGeneratorPos, 1);
                RemoveInternalChildRange(i, 1);
            }
            return desiredSize;
        }
开发者ID:rexperalta,项目名称:OCTGN,代码行数:48,代码来源:PilePanel.cs

示例5: RemoveChildRange

        // THE HACK implementation. A copy from Microsofts VirtualizingStackPanel
        void RemoveChildRange(GeneratorPosition position, int itemCount, int itemUICount) {
            if (IsItemsHost) {
                UIElementCollection children = InternalChildren;
                int pos = position.Index;
                if (position.Offset > 0) {
                    // An item is being removed after the one at the index 
                    pos++;
                }

                if (pos < children.Count) {
                    int uiCount = itemUICount;
                    Debug.Assert((itemCount == itemUICount) || (itemUICount == 0),
                        "Both ItemUICount and ItemCount should be equal or ItemUICount should be 0.");
                    if (uiCount > 0) {
                        RemoveInternalChildRange(pos, uiCount);
                        //VirtualizingPanel.RemoveInternalChildRange(children, pos, uiCount);

                        //if (IsVirtualizing && InRecyclingMode) {
                        //_realizedChildren.RemoveRange(pos, uiCount);
                        //}
                    }
                }
            }
        }
开发者ID:SIXNetworks,项目名称:withSIX.Desktop,代码行数:25,代码来源:CustomVirtualizingWrapPanel.cs

示例6: OnItemMoved

        void OnItemMoved(object item, int oldIndex, int newIndex)
        {
            if (_itemMap == null)
            {
                // reentrant call (from RemoveAllInternal) shouldn't happen,
                // but if it does, don't crash
                Debug.Assert(false, "unexpected reentrant call to OnItemMoved");
                return;
            }

            DependencyObject container = null;    // the corresponding container
            int containerCount = 0;
            UnrealizedItemBlock uib;

            // search for the moved item
            GeneratorPosition position;
            ItemBlock block;
            int offsetFromBlockStart;
            int correctIndex;
            GetBlockAndPosition(item, oldIndex, true, out position, out block, out offsetFromBlockStart, out correctIndex);

            GeneratorPosition oldPosition = position;

            RealizedItemBlock rib = block as RealizedItemBlock;
            if (rib != null)
            {
                containerCount = 1;
                container = rib.ContainerAt(offsetFromBlockStart);
            }

            // remove the item, and remove the block if it's now empty
            MoveItems(block, offsetFromBlockStart + 1, block.ItemCount - offsetFromBlockStart - 1, block, offsetFromBlockStart, 0);
            --block.ItemCount;
            RemoveAndCoalesceBlocksIfNeeded(block);

            //
            // now insert into the new spot.
            //

            position = new GeneratorPosition(-1,0);
            block = _itemMap.Next;
            offsetFromBlockStart = newIndex;
            while (block != _itemMap && offsetFromBlockStart >= block.ItemCount)
            {
                offsetFromBlockStart -= block.ItemCount;
                if (block.ContainerCount > 0)
                {
                    position.Index += block.ContainerCount;
                    position.Offset = 0;
                }
                else
                {
                    position.Offset += block.ItemCount;
                }
                block = block.Next;
            }

            position.Offset += offsetFromBlockStart + 1;

            // if it's an unrealized block, add the item by bumping the count
            uib = block as UnrealizedItemBlock;
            if (uib != null)
            {
                MoveItems(uib, offsetFromBlockStart, 1, uib, offsetFromBlockStart+1, 0);
                ++ uib.ItemCount;
            }

            // if the item can be added to a previous unrealized block, do so
            else if ((offsetFromBlockStart == 0 || block == _itemMap) &&
                    ((uib = block.Prev as UnrealizedItemBlock) != null))
            {
                ++ uib.ItemCount;
            }

            // otherwise, create a new unrealized block
            else
            {
                uib = new UnrealizedItemBlock();
                uib.ItemCount = 1;

                // split the current realized block, if necessary
                if (offsetFromBlockStart > 0 && (rib = block as RealizedItemBlock) != null)
                {
                    RealizedItemBlock newBlock = new RealizedItemBlock();
                    MoveItems(rib, offsetFromBlockStart, rib.ItemCount - offsetFromBlockStart, newBlock, 0, offsetFromBlockStart);
                    newBlock.InsertAfter(rib);
                    position.Index += block.ContainerCount;
                    position.Offset = 1;
                    offsetFromBlockStart = 0;
                    block = newBlock;
                }

                uib.InsertBefore(block);
            }

            DependencyObject parent = VisualTreeHelper.GetParentInternal(container);

            // tell layout what happened
            if (ItemsChanged != null)
            {
//.........这里部分代码省略.........
开发者ID:mind0n,项目名称:hive,代码行数:101,代码来源:ItemContainerGenerator.cs

示例7: OnItemAdded

        // Called when an item is added to the items collection
        void OnItemAdded(object item, int index)
        {
            if (_itemMap == null)
            {
                // reentrant call (from RemoveAllInternal) shouldn't happen,
                // but if it does, don't crash
                Debug.Assert(false, "unexpected reentrant call to OnItemAdded");
                return;
            }

            ValidateAndCorrectIndex(item, ref index);

            GeneratorPosition position = new GeneratorPosition(-1,0);

            // find the block containing the new item
            ItemBlock block = _itemMap.Next;
            int offset = index;
            while (block != _itemMap && offset >= block.ItemCount)
            {
                offset -= block.ItemCount;
                position.Index += block.ContainerCount;
                block = block.Next;
            }

            position.Offset = offset + 1;

            // if it's an unrealized block, add the item by bumping the count
            UnrealizedItemBlock uib = block as UnrealizedItemBlock;
            if (uib != null)
            {
                MoveItems(uib, offset, 1, uib, offset+1, 0);
                ++ uib.ItemCount;
            }

            // if the item can be added to a previous unrealized block, do so
            else if ((offset == 0 || block == _itemMap) &&
                    ((uib = block.Prev as UnrealizedItemBlock) != null))
            {
                ++ uib.ItemCount;
            }

            // otherwise, create a new unrealized block
            else
            {
                uib = new UnrealizedItemBlock();
                uib.ItemCount = 1;

                // split the current realized block, if necessary
                RealizedItemBlock rib;
                if (offset > 0 && (rib = block as RealizedItemBlock) != null)
                {
                    RealizedItemBlock newBlock = new RealizedItemBlock();
                    MoveItems(rib, offset, rib.ItemCount - offset, newBlock, 0, offset);
                    newBlock.InsertAfter(rib);
                    position.Index += block.ContainerCount;
                    position.Offset = 1;
                    block = newBlock;
                }

                uib.InsertBefore(block);
            }

            // tell generators what happened
            if (MapChanged != null)
            {
                MapChanged(null, index, +1, uib, 0, 0);
            }

            // tell layout what happened
            if (ItemsChanged != null)
            {
                ItemsChanged(this, new ItemsChangedEventArgs(NotifyCollectionChangedAction.Add, position, 1, 0));
            }
        }
开发者ID:mind0n,项目名称:hive,代码行数:75,代码来源:ItemContainerGenerator.cs

示例8: GetBlockAndPosition

        void GetBlockAndPosition(object item, bool deletedFromItems, out GeneratorPosition position, out ItemBlock block, out int offsetFromBlockStart, out int correctIndex)
        {
            correctIndex = 0;
            int containerIndex = 0;
            offsetFromBlockStart = 0;
            int deletionOffset = deletedFromItems ? 1 : 0;
            position = new GeneratorPosition(-1, 0);

            if (_itemMap == null)
            {
                // handle reentrant call
                block = null;
                return;
            }

            for (block = _itemMap.Next;  block != _itemMap;  block = block.Next)
            {
                UnrealizedItemBlock uib;
                RealizedItemBlock rib = block as RealizedItemBlock;

                if (rib != null)
                {
                    // compare realized items with item for which we are searching
                    offsetFromBlockStart = rib.OffsetOfItem(item);
                    if (offsetFromBlockStart >= 0)
                    {
                        position = new GeneratorPosition(containerIndex + offsetFromBlockStart, 0);
                        correctIndex += offsetFromBlockStart;
                        break;
                    }
                }
                else if ((uib = block as UnrealizedItemBlock) != null)
                {
                    // if the item isn't realized, we can't find it
                    // directly.  Instead, look for indirect evidence that it
                    // belongs to this block by checking the indices of
                    // nearby realized items.

#if DEBUG
                    // Sanity check - make sure data structure is OK so far.
                    rib = block.Prev as RealizedItemBlock;
                    if (rib != null && rib.ContainerCount > 0)
                    {
                        Debug.Assert(Object.Equals(rib.ItemAt(rib.ContainerCount - 1),
                                                    ItemsInternal[correctIndex - 1]),
                                    "Generator data structure is corrupt");
                    }
#endif

                    bool itemIsInCurrentBlock = false;
                    rib = block.Next as RealizedItemBlock;
                    if (rib != null && rib.ContainerCount > 0)
                    {
                        // if the index of the next realized item is off by one,
                        // the deleted item likely comes from the current
                        // unrealized block.
                        itemIsInCurrentBlock =
                                Object.Equals(rib.ItemAt(0),
                                    ItemsInternal[correctIndex + block.ItemCount - deletionOffset]);
                    }
                    else if (block.Next == _itemMap)
                    {
                        // similarly if we're at the end of the list and the
                        // overall count is off by one, or if the current block
                        // is the only block, the deleted item likely
                        // comes from the current (last) unrealized block
                        itemIsInCurrentBlock = block.Prev == _itemMap ||
                            (ItemsInternal.Count == correctIndex + block.ItemCount - deletionOffset);
                    }

                    if (itemIsInCurrentBlock)
                    {
                        // we don't know where it is in this block, so assume
                        // it's the very first item.
                        offsetFromBlockStart = 0;
                        position = new GeneratorPosition(containerIndex-1, 1);
                        break;
                    }
                }

                correctIndex += block.ItemCount;
                containerIndex += block.ContainerCount;
            }

            if (block == _itemMap)
            {
                // There's no way of knowing which unrealized block it belonged to, so
                // the data structure can't be updated correctly.  Sound the alarm.
                throw new InvalidOperationException(SR.Get(SRID.CannotFindRemovedItem));
            }
        }
开发者ID:mind0n,项目名称:hive,代码行数:91,代码来源:ItemContainerGenerator.cs

示例9: HandleDetailReset

    private void HandleDetailReset( object masterItem, DetailGeneratorNode detailNode )
    {
      GeneratorNodeHelper nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 );
      int masterIndex = nodeHelper.FindItem( masterItem );

      // -1 means either taht the master item is below a collapsed group node, or that the item does not exists, validate.
      if( masterIndex == -1 )
      {
        nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 );
        if( !nodeHelper.Contains( masterItem ) )
          throw new DataGridInternalException();
      }

      ItemsGeneratorNode masterNode = nodeHelper.CurrentNode as ItemsGeneratorNode;

      Debug.Assert( masterNode != null, "masterNode != null" );
#if LOG
      Log.Assert( this, masterNode != null, "masterNode != null" );
#endif

      //start index will be ignored later on if the masterIndex is -1!!
      int startIndex = nodeHelper.Index + masterNode.IndexOf( masterItem ) + 1; //details start a master index + 1

      List<DetailGeneratorNode> detailsForMaster = null;

      //edge case, it is possible to receive a Reset from Floating details!
      if( masterNode.Details == null )
      {
        //check for floating details, if not present, throw, this is an abnormal case.
        if( !m_floatingDetails.Contains( masterItem ) )
        {
          throw new DataGridInternalException();
        }
      }
      else
      {
        masterNode.Details.TryGetValue( masterNode.Items.IndexOf( masterItem ), out detailsForMaster );

        Debug.Assert( detailsForMaster != null, "detailsForMaster != null" );
#if LOG
        Log.Assert( this, detailsForMaster != null, "detailsForMaster != null" );
#endif
      }

      if( detailsForMaster != null )
      {
        //this is required to ensure that if the details that resets is not the first one, the index is calculated appropriatly.
        foreach( DetailGeneratorNode node in detailsForMaster )
        {
          if( node == detailNode )
          {
            break;
          }
          else
          {
            startIndex += node.ItemCount;
          }
        }

        //if there were 'items' in the detail node, process the remove of them
        int oldDetailCount = detailNode.ItemCount;
        if( oldDetailCount > 0 )
        {
          int endIndex = startIndex + oldDetailCount - 1; //last detail index

          GeneratorPosition removeGenPos = ( masterIndex != -1 )
            ? this.GeneratorPositionFromIndex( startIndex )
            : new GeneratorPosition( -1, 1 );

          int genRemCount = 0;

          List<DependencyObject> removedContainers = new List<DependencyObject>();

          //this has no uses if the masterIndex is -1 ( collapsed master item )
          if( masterIndex != -1 )
          {
            genRemCount = this.RemoveGeneratedItems( startIndex, endIndex, removedContainers );
          }

          masterNode.AdjustItemCount( -oldDetailCount );

          this.IncrementCurrentGenerationCount();

          //this has no uses if the masterIndex is -1 ( collapsed master item )
          if( masterIndex != -1 )
          {
            this.SendRemoveEvent( removeGenPos, masterIndex + 1, oldDetailCount, genRemCount, removedContainers );
          }
        }

        detailNode.UpdateItemCount();

        int newDetailCount = detailNode.ItemCount;
        if( newDetailCount > 0 )
        {
          GeneratorPosition addGenPos = new GeneratorPosition( -1, 1 );

          //this has no uses if the masterIndex is -1 ( collapsed master item )
          if( masterIndex != -1 )
          {
//.........这里部分代码省略.........
开发者ID:wangws556,项目名称:duoduo-chat,代码行数:101,代码来源:CustomItemContainerGenerator.cs

示例10:

        /// <summary>
        /// Map a GeneratorPosition to an index into the items collection.
        /// </summary>
        int IItemContainerGenerator.IndexFromGeneratorPosition(GeneratorPosition position)
        {
            int index = position.Index;

            if (index == -1)
            {
                // offset is relative to the fictitious boundary item
                if (position.Offset >= 0)
                {
                    return position.Offset - 1;
                }
                else
                {
                    return ItemsInternal.Count + position.Offset;
                }
            }

            if (_itemMap != null)
            {
                int itemIndex = 0;      // number of items we've skipped over

                // locate container at the given index
                for (ItemBlock block = _itemMap.Next;  block != _itemMap;  block = block.Next)
                {
                    if (index < block.ContainerCount)
                    {
                        // container is within this block.  return the answer
                        return itemIndex + index + position.Offset;
                    }
                    else
                    {
                        // skip over this block
                        itemIndex += block.ItemCount;
                        index -= block.ContainerCount;
                    }
                }
            }

            return -1;
        }
开发者ID:mind0n,项目名称:hive,代码行数:43,代码来源:ItemContainerGenerator.cs

示例11: OnRefresh

        // Called when the items collection is refreshed
        void OnRefresh()
        {
            ((IItemContainerGenerator)this).RemoveAll();

            // tell layout what happened
            if (ItemsChanged != null)
            {
                GeneratorPosition position = new GeneratorPosition(0, 0);
                ItemsChanged(this, new ItemsChangedEventArgs(NotifyCollectionChangedAction.Reset, position, 0, 0));
            }
        }
开发者ID:mind0n,项目名称:hive,代码行数:12,代码来源:ItemContainerGenerator.cs

示例12: MoveToPosition

        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        void MoveToPosition(GeneratorPosition position, GeneratorDirection direction, bool allowStartAtRealizedItem, ref GeneratorState state)
        {
            ItemBlock block = _itemMap;
            if (block == null)
                return;         // this can happen in event-leapfrogging situations (Dev11 283413)

            int itemIndex = 0;

            // first move to the indexed (realized) item
            if (position.Index != -1)
            {
                // find the right block
                int itemCount = 0;
                int index = position.Index;
                block = block.Next;
                while (index >= block.ContainerCount)
                {
                    itemCount += block.ItemCount;
                    index -= block.ContainerCount;
                    itemIndex += block.ItemCount;
                    block = block.Next;
                }

                // set the position
                state.Block = block;
                state.Offset = index;
                state.Count = itemCount;
                state.ItemIndex = itemIndex + index;
            }
            else
            {
                state.Block = block;
                state.Offset = 0;
                state.Count = 0;
                state.ItemIndex = itemIndex - 1;
            }

            // adjust the offset - we always set the state so it points to the next
            // item to be generated.
            int offset = position.Offset;
            if (offset == 0 && (!allowStartAtRealizedItem || state.Block == _itemMap))
            {
                offset = (direction == GeneratorDirection.Forward) ? 1 : -1;
            }

            // advance the state according to the offset
            if (offset > 0)
            {
                state.Block.MoveForward(ref state, true);
                -- offset;

                while (offset > 0)
                {
                    offset -= state.Block.MoveForward(ref state, allowStartAtRealizedItem, offset);
                }
            }
            else if (offset < 0)
            {
                if (state.Block == _itemMap)
                {
                    state.ItemIndex = state.Count = ItemsInternal.Count;
                }

                state.Block.MoveBackward(ref state, true);
                ++ offset;

                while (offset < 0)
                {
                    offset += state.Block.MoveBackward(ref state, allowStartAtRealizedItem, -offset);
                }
            }
        }
开发者ID:mind0n,项目名称:hive,代码行数:78,代码来源:ItemContainerGenerator.cs

示例13: Generator

            //------------------------------------------------------
            //
            //  Constructors
            //
            //------------------------------------------------------

            internal Generator(ItemContainerGenerator factory, GeneratorPosition position, GeneratorDirection direction, bool allowStartAtRealizedItem)
            {
                _factory = factory;
                _direction = direction;

                _factory.MapChanged += new MapChangedHandler(OnMapChanged);

                _factory.MoveToPosition(position, direction, allowStartAtRealizedItem, ref _cachedState);
                _done = (_factory.ItemsInternal.Count == 0);

                _factory.SetStatus(GeneratorStatus.GeneratingContainers);
            }
开发者ID:mind0n,项目名称:hive,代码行数:18,代码来源:ItemContainerGenerator.cs

示例14: CleanUpItems

 private void CleanUpItems(int minDesiredGenerated, int maxDesiredGenerated)
 {
     var generator = ItemContainerGenerator;
     for (var i = InternalChildren.Count - 1; i >= 0; i--)
     {
         var childGeneratorPos = new GeneratorPosition(i, 0);
         var itemIndex = generator.IndexFromGeneratorPosition(childGeneratorPos);
         if (itemIndex < minDesiredGenerated || itemIndex > maxDesiredGenerated)
         {
             RemoveInternalChildRange(i, 1);
             generator.Remove(childGeneratorPos, 1);
         }
     }
 }
开发者ID:Ghawken,项目名称:FrontView,代码行数:14,代码来源:VirtElementFlow.cs

示例15: CustomItemContainerGeneratorDisposableDisposer

      public CustomItemContainerGeneratorDisposableDisposer( CustomItemContainerGenerator generator, GeneratorPosition startGenPos, GeneratorDirection direction )
      {
        if( generator == null )
        {
          throw new ArgumentNullException( "generator" );
        }

        m_generator = generator;

        m_generator.StartGenerator( startGenPos, direction );
      }
开发者ID:wangws556,项目名称:duoduo-chat,代码行数:11,代码来源:CustomItemContainerGenerator.cs


注:本文中的System.Windows.Controls.Primitives.GeneratorPosition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。