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


C# TextPointer.GetAdjacentElementFromOuterPosition方法代码示例

本文整理汇总了C#中System.Windows.Documents.TextPointer.GetAdjacentElementFromOuterPosition方法的典型用法代码示例。如果您正苦于以下问题:C# TextPointer.GetAdjacentElementFromOuterPosition方法的具体用法?C# TextPointer.GetAdjacentElementFromOuterPosition怎么用?C# TextPointer.GetAdjacentElementFromOuterPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.TextPointer的用法示例。


在下文中一共展示了TextPointer.GetAdjacentElementFromOuterPosition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoCore

        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        // Called by the undo manager.  Restores tree state to its condition
        // when the unit was created.  Assumes the tree state matches conditions
        // just after the unit was created.
        public override void DoCore()
        {
            TextPointer start;
            TextPointer end;
            TextElement element;

            VerifyTreeContentHashCode();

            start = new TextPointer(this.TextContainer, this.SymbolOffset, LogicalDirection.Forward);

            Invariant.Assert(start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart, "TextTree undo unit out of [....] with TextTree.");

            element = start.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);

            if (_deep)
            {
                // Extract the element and its content.
                end = new TextPointer(this.TextContainer, element.TextElementNode, ElementEdge.AfterEnd);
                this.TextContainer.DeleteContentInternal(start, end);
            }
            else
            {
                // Just extract the element, not its content.
                this.TextContainer.ExtractElementInternal(element);
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:37,代码来源:TextTreeInsertElementUndoUnit.cs

示例2: InputHitTest

        // ------------------------------------------------------------------ 
        //  Hit tests to the correct ContentElement within the line.
        //
        //      offset - offset within the line.
        // 
        // Returns: ContentElement which has been hit.
        // ----------------------------------------------------------------- 
        internal override IInputElement InputHitTest(double offset) 
        {
            TextContainer tree; 
            DependencyObject element;
            CharacterHit charHit;
            TextPointer position;
            TextPointerContext type = TextPointerContext.None; 

            element = null; 
 
            // We can only support hittesting text elements in a TextContainer.
            // If the TextContainer is not a TextContainer, return null which higher up the stack 
            // will be converted into a reference to the control itself.
            tree = _owner.TextContainer as TextContainer;

            // Adjusted offset for shift due to trailing spaces rendering 
            double delta = CalculateXOffsetShift();
            if (tree != null) 
            { 
                if (_line.HasOverflowed && _owner.ParagraphProperties.TextTrimming != TextTrimming.None)
                { 
                    // We should not shift offset in this case
                    Invariant.Assert(DoubleUtil.AreClose(delta, 0));
                    System.Windows.Media.TextFormatting.TextLine line = _line.Collapse(GetCollapsingProps(_wrappingWidth, _owner.ParagraphProperties));
                    Invariant.Assert(line.HasCollapsed, "Line has not been collapsed"); 

                    // Get TextPointer from specified distance. 
                    charHit = line.GetCharacterHitFromDistance(offset); 
                }
                else 
                {

                    charHit = _line.GetCharacterHitFromDistance(offset - delta);
                } 

                position = new TextPointer(_owner.ContentStart, CalcPositionOffset(charHit), LogicalDirection.Forward); 
 
                if (position != null)
                { 
                    if (charHit.TrailingLength == 0)
                    {
                        // Start of character. Look forward
                        type = position.GetPointerContext(LogicalDirection.Forward); 
                    }
                    else 
                    { 
                        // End of character. Look backward
                        type = position.GetPointerContext(LogicalDirection.Backward); 
                    }

                    // Get element only for Text & Start/End element, for all other positions
                    // return null (it means that the line owner has been hit). 
                    if (type == TextPointerContext.Text || type == TextPointerContext.ElementEnd)
                    { 
                        element = position.Parent as TextElement; 
                    }
                    else if (type == TextPointerContext.ElementStart) 
                    {
                        element = position.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);
                    }
                } 
            }
 
            return element as IInputElement; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:72,代码来源:ComplexLine.cs

示例3: CreateImplicitRun

        // Helper for EnsureInsertionPosition, inserts a Run element at this position. 
        private static TextPointer CreateImplicitRun(TextPointer position)
        { 
            TextPointer insertionPosition;

            if (position.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward) is Run)
            { 
                insertionPosition = position.CreatePointer();
                insertionPosition.MoveToNextContextPosition(LogicalDirection.Forward); 
                insertionPosition.Freeze(); 
            }
            else if (position.GetAdjacentElementFromOuterPosition(LogicalDirection.Backward) is Run) 
            {
                insertionPosition = position.CreatePointer();
                insertionPosition.MoveToNextContextPosition(LogicalDirection.Backward);
                insertionPosition.Freeze(); 
            }
            else 
            { 
                Run implicitRun = Run.CreateImplicitRun(position.Parent);
                implicitRun.Reposition(position, position); 
                insertionPosition = implicitRun.ContentStart.GetFrozenPointer(position.LogicalDirection); // return a position with the same orientation inside a Run
            }

            return insertionPosition; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:26,代码来源:TextRangeEditTables.cs

示例4: ValidateChild

        internal static bool ValidateChild(TextPointer position, Type childType, bool throwIfIllegalChild, bool throwIfIllegalHyperlinkDescendent)
        {
            DependencyObject parent = position.Parent;

            if (parent == null)
            {
                TextElement leftElement = position.GetAdjacentElementFromOuterPosition(LogicalDirection.Backward);
                TextElement rightElement = position.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);
                return (leftElement == null || IsValidSibling(leftElement.GetType(), childType)) && 
                    (rightElement == null || IsValidSibling(rightElement.GetType(), childType));
            }

            if (parent is TextElement)
            {
                return ValidateChild((TextElement)parent, childType, throwIfIllegalChild, throwIfIllegalHyperlinkDescendent);
            }

            bool isValidChild = IsValidChild(parent.GetType(), childType);

            if (!isValidChild && throwIfIllegalChild)
            {
                throw new InvalidOperationException(SR.Get(SRID.TextSchema_ChildTypeIsInvalid, parent.GetType().Name, childType.Name));
            }

            return isValidChild;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:26,代码来源:TextSchema.cs

示例5: GetListItemIndex

        //--------------------------------------------------------------------
        //
        //  Internal Methods
        // 
        //--------------------------------------------------------------------
 
        #region Internal Methods 

        /// <summary> 
        /// Returns the integer "index" of a specified ListItem that is an immediate child of
        /// this List. This index is defined to be a sequential counter of ListElementItems only
        /// (skipping other elements) among this List's immediate children.
        /// 
        /// The list item index of the first child of type ListItem is specified by
        /// this.StartListIndex, which has a default value of 1. 
        /// 
        /// The index returned by this method is used in the formation of some ListItem
        /// markers such as "(b)" and "viii." (as opposed to others, like disks and wedges, 
        /// which are not sequential-position-dependent).
        /// </summary>
        /// <param name="item">The item whose index is to be returned.</param>
        /// <returns>Returns the index of a specified ListItem.</returns> 
        internal int GetListItemIndex(ListItem item)
        { 
            // Check for valid arg 
            if (item == null)
            { 
                throw new ArgumentNullException("item");
            }
            if (item.Parent != this)
            { 
                throw new InvalidOperationException(SR.Get(SRID.ListElementItemNotAChildOfList));
            } 
 
            // Count ListItem siblings (not other element types) back to first item.
            int itemIndex = StartIndex; 
            TextPointer textNav = new TextPointer(this.ContentStart);
            while (textNav.CompareTo(this.ContentEnd) != 0)
            {
                // ListItem is a content element, so look for ElementStart runs only 
                if (textNav.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart)
                { 
                    DependencyObject element = textNav.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward); 
                    if (element is ListItem)
                    { 
                        if (element == item)
                        {
                            break;
                        } 
                        if (itemIndex < int.MaxValue)
                        { 
                            ++itemIndex; 
                        }
                    } 
                    // Skip entire content element content, because we are looking
                    // only for immediate children.
                    textNav.MoveToPosition(((TextElement)element).ElementEnd);
                } 
                else
                { 
                    textNav.MoveToNextContextPosition(LogicalDirection.Forward); 
                }
            } 
            return itemIndex;
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:65,代码来源:List.cs


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