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


C# TextPointer.MoveToNextContextPosition方法代码示例

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


在下文中一共展示了TextPointer.MoveToNextContextPosition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
            end = new TextPointer(this.TextContainer, this.SymbolOffset + _symbolCount - 2, LogicalDirection.Forward);

            // Insert a new element.
            element = (TextElement)Activator.CreateInstance(_type);
            element.Reposition(start, end);

            // Restore local resources
            element.Resources = _resources;

            // Move end into the scope of the new element.
            end.MoveToNextContextPosition(LogicalDirection.Backward);
            // Then restore local property values.
            // 
            this.TextContainer.SetValues(end, ArrayToLocalValueEnumerator(_localValues));

            if (element is Table)
            {
                TextTreeDeleteContentUndoUnit.RestoreColumns((Table)element, _columns);
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:40,代码来源:TextTreeExtractElementUndoUnit.cs

示例2: FindElementPosition

        //-------------------------------------------------------------------
        // IContentHost Helpers
        //-------------------------------------------------------------------

        /// <summary>
        /// Searches for an element in the _structuralCache.TextContainer. If the element is found, returns the
        /// position at which it is found. Otherwise returns null.
        /// </summary>
        /// <param name="e">
        /// Element to be found.
        /// </param>
        /// <param name="isLimitedToTextView">
        /// bool value indicating whether the search should only be limited to the text view of the page,
        /// in which case we search only text segments in the text view
        /// </param>
        private TextPointer FindElementPosition(IInputElement e, bool isLimitedToTextView)
        {
            // Parameter validation
            Debug.Assert(e != null);

            // Validate that this function is only called when a TextContainer exists as complex content
            Debug.Assert(_structuralCache.TextContainer is TextContainer);

            TextPointer elementPosition = null;

            // If e is a TextElement we can optimize by checking its TextContainer
            if (e is TextElement)
            {
                if ((e as TextElement).TextContainer == _structuralCache.TextContainer)
                {
                    // Element found
                    elementPosition = new TextPointer((e as TextElement).ElementStart);
                }
                // else: elementPosition stays null
            }
            else
            {
                // Else: search for e in the complex content
                if (!(_structuralCache.TextContainer.Start is TextPointer) ||
                    !(_structuralCache.TextContainer.End is TextPointer))
                {
                    // Invalid TextContainer, don't search
                    return null;
                }

                TextPointer searchPosition = new TextPointer(_structuralCache.TextContainer.Start as TextPointer);
                while (elementPosition == null && ((ITextPointer)searchPosition).CompareTo(_structuralCache.TextContainer.End) < 0)
                {
                    // Search each position in _structuralCache.TextContainer for the element
                    switch (searchPosition.GetPointerContext(LogicalDirection.Forward))
                    {
                        case TextPointerContext.EmbeddedElement:
                            DependencyObject embeddedObject = searchPosition.GetAdjacentElement(LogicalDirection.Forward);
                            if (embeddedObject is ContentElement || embeddedObject is UIElement)
                            {
                                if (embeddedObject == e as ContentElement || embeddedObject == e as UIElement)
                                {
                                    // Element found. Stop searching
                                    elementPosition = new TextPointer(searchPosition);
                                    break;
                                }
                            }
                            break;
                        default:
                            break;
                    }
                    searchPosition.MoveToNextContextPosition(LogicalDirection.Forward);
                }
            }

            // If the element was found, check if we are limited to text view
            if (elementPosition != null)
            {
                if (isLimitedToTextView)
                {
                    // At this point, we should create TextView if it doesn't exist
                    _textView = GetTextView();
                    Invariant.Assert(_textView != null);
                    // Check all segements in text view for position
                    for (int segmentIndex = 0; segmentIndex < ((ITextView)_textView).TextSegments.Count; segmentIndex++)
                    {
                        if (((ITextPointer)elementPosition).CompareTo(((ITextView)_textView).TextSegments[segmentIndex].Start) >= 0 &&
                            ((ITextPointer)elementPosition).CompareTo(((ITextView)_textView).TextSegments[segmentIndex].End) < 0)
                        {
                            // Element lies within a segment. Return position
                            return elementPosition;
                        }
                    }
                    // Element not found in all segments of TextView. Set position to null
                    elementPosition = null;
                }
            }
            return elementPosition;
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:94,代码来源:FlowDocumentPage.cs

示例3: Do

            // Inserts the content held by this container at a specified position.
            // Navigator is positioned just past the new content on return.
            // Navigator is expected to have forward gravity.
            internal override void Do(TextPointer navigator)
            {
                ContentContainer container;
                TextElement element;

                // Insert the element.
                element = (TextElement)Activator.CreateInstance(_elementType);
                element.Reposition(navigator, navigator);

                // Get inside its scope.
                navigator.MoveToNextContextPosition(LogicalDirection.Backward);

                // Set local values.
                // 
                navigator.TextContainer.SetValues(navigator, TextTreeUndoUnit.ArrayToLocalValueEnumerator(_localValues));

                // Restore resources
                element.Resources = _resources;

                // Insert contained content.
                for (container = _childContainer; container != null; container = container.NextContainer)
                {
                    container.Do(navigator);
                }

                // Move outside the element's scope again.
                navigator.MoveToNextContextPosition(LogicalDirection.Forward);
            }
开发者ID:JianwenSun,项目名称:cc,代码行数:31,代码来源:TextTreeDeleteContentUndoUnit.cs

示例4: UpdateAccessKey

        /// <summary>
        /// UpdateAccessKey - Scans forward in the tree looking for the access key marker, replacing it with access key element. We only support one find.
        /// </summary>
        private void UpdateAccessKey()
        {
            TextPointer navigator = new TextPointer(TextContainer.Start);

            while (!_accessKeyLocated && navigator.CompareTo(TextContainer.End) < 0 )
            {
                TextPointerContext symbolType = navigator.GetPointerContext(LogicalDirection.Forward);
                switch (symbolType)
                {
                    case TextPointerContext.Text:
                        string text = navigator.GetTextInRun(LogicalDirection.Forward);
                        int index = FindAccessKeyMarker(text);
                        if(index != -1 && index < text.Length - 1)
                        {
                            string keyText = StringInfo.GetNextTextElement(text, index + 1);
                            TextPointer keyEnd = navigator.GetPositionAtOffset(index + 1 + keyText.Length);

                            _accessKey = new Run(keyText);
                            _accessKey.Style = AccessKeyStyle;

                            RegisterAccessKey();

                            HasCustomSerializationStorage.SetValue(_accessKey, true);
                            _accessKeyLocated = true;

                            UninitializeTextContainerListener();

                            TextContainer.BeginChange();
                            try
                            {
                                TextPointer underlineStart = new TextPointer(navigator, index);
                                TextRangeEdit.DeleteInlineContent(underlineStart, keyEnd);
                                _accessKey.RepositionWithContent(underlineStart);

                            }
                            finally
                            {
                                TextContainer.EndChange();
                                InitializeTextContainerListener();
                            }
                        }

                        break;
                }
                navigator.MoveToNextContextPosition(LogicalDirection.Forward);
            }

            // Convert double _ to single _
            navigator = new TextPointer(TextContainer.Start);
            string accessKeyMarker = AccessKeyMarker.ToString();
            string doubleAccessKeyMarker = accessKeyMarker + accessKeyMarker;
            while (navigator.CompareTo(TextContainer.End) < 0)
            {
                TextPointerContext symbolType = navigator.GetPointerContext(LogicalDirection.Forward);
                switch (symbolType)
                {
                    case TextPointerContext.Text:
                        string text = navigator.GetTextInRun(LogicalDirection.Forward);
                        string nexText = text.Replace(doubleAccessKeyMarker, accessKeyMarker);
                        if (text != nexText)
                        {
                            TextPointer keyStart = new TextPointer(navigator, 0);
                            TextPointer keyEnd = new TextPointer(navigator, text.Length);

                            UninitializeTextContainerListener();
                            TextContainer.BeginChange();
                            try
                            {
                                keyEnd.InsertTextInRun(nexText);
                                TextRangeEdit.DeleteInlineContent(keyStart, keyEnd);
                            }
                            finally
                            {
                                TextContainer.EndChange();
                                InitializeTextContainerListener();
                            }
                        }

                        break;
                }
                navigator.MoveToNextContextPosition(LogicalDirection.Forward);
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:86,代码来源:AccessText.cs

示例5: DeleteEquiScopedContent

        /// <summary>
        /// Deletes all equi-scoped segments of content from start TextPointer 
        /// up to fragment root. Thus clears one half of a fragment. 
        /// The other half remains untouched.
        /// All elements whose boundaries are crossed by this range 
        /// remain in the tree (except for emptied formatting elements).
        /// </summary>
        /// <param name="start">
        /// A position from which content clearinng starts. 
        /// All content segments between this position and a fragment
        /// root will be deleted. 
        /// </param> 
        /// <param name="end">
        /// A position indicating the other boundary of a fragment. 
        /// This position is used for fragment root identification.
        /// </param>
        private static void DeleteEquiScopedContent(TextPointer start, TextPointer end)
        { 
            // Validate parameters
            Invariant.Assert(start != null, "null check: start"); 
            Invariant.Assert(end != null, "null check: end"); 

            if (start.CompareTo(end) == 0) 
            {
                return;
            }
 
            if (start.Parent == end.Parent)
            { 
                DeleteContentBetweenPositions(start, end); 
                return;
            } 

            // Identify directional parameters
            LogicalDirection direction;
            LogicalDirection oppositeDirection; 
            TextPointerContext enterScopeSymbol;
            TextPointerContext leaveScopeSymbol; 
            ElementEdge edgeBeforeElement; 
            ElementEdge edgeAfterElement;
            if (start.CompareTo(end) < 0) 
            {
                direction = LogicalDirection.Forward;
                oppositeDirection = LogicalDirection.Backward;
                enterScopeSymbol = TextPointerContext.ElementStart; 
                leaveScopeSymbol = TextPointerContext.ElementEnd;
                edgeBeforeElement = ElementEdge.BeforeStart; 
                edgeAfterElement = ElementEdge.AfterEnd; 
            }
            else 
            {
                direction = LogicalDirection.Backward;
                oppositeDirection = LogicalDirection.Forward;
                enterScopeSymbol = TextPointerContext.ElementEnd; 
                leaveScopeSymbol = TextPointerContext.ElementStart;
                edgeBeforeElement = ElementEdge.AfterEnd; 
                edgeAfterElement = ElementEdge.BeforeStart; 
            }
 
            // previousPosition will store a location where nondeleted content starts
            TextPointer previousPosition = new TextPointer(start);
            // nextPosition runs toward other end until level change -
            // so that we could delete all content from previousPosition 
            // to nextPosition at once.
            TextPointer nextPosition = new TextPointer(start); 
 
            // Run nextPosition forward until the very end of affected range
            while (nextPosition.CompareTo(end) != 0) 
            {
                Invariant.Assert(direction == LogicalDirection.Forward && nextPosition.CompareTo(end) < 0 || direction == LogicalDirection.Backward && nextPosition.CompareTo(end) > 0,
                    "Inappropriate position ordering");
                Invariant.Assert(previousPosition.Parent == nextPosition.Parent, "inconsistent position Parents: previous and next"); 

                TextPointerContext pointerContext = nextPosition.GetPointerContext(direction); 
 
                if (pointerContext == TextPointerContext.Text || pointerContext == TextPointerContext.EmbeddedElement)
                { 
                    // Add this run to a collection of equi-scoped content
                    nextPosition.MoveToNextContextPosition(direction);

                    // Check if we went too far and return a little to end if necessary 
                    if (direction == LogicalDirection.Forward && nextPosition.CompareTo(end) > 0 || direction == LogicalDirection.Backward && nextPosition.CompareTo(end) < 0)
                    { 
                        Invariant.Assert(nextPosition.Parent == end.Parent, "inconsistent poaition Parents: next and end"); 
                        nextPosition.MoveToPosition(end);
                        break; 
                    }
                }
                else if (pointerContext == enterScopeSymbol)
                { 
                    // Jump over the element and continue collecting equi-scoped content
                    nextPosition.MoveToNextContextPosition(direction); 
                    ((ITextPointer)nextPosition).MoveToElementEdge(edgeAfterElement); 

                    // If our range crosses the element then we stop before its opening tag 
                    if (direction == LogicalDirection.Forward && nextPosition.CompareTo(end) >= 0 || direction == LogicalDirection.Backward && nextPosition.CompareTo(end) <= 0)
                    {
                        nextPosition.MoveToNextContextPosition(oppositeDirection);
                        ((ITextPointer)nextPosition).MoveToElementEdge(edgeBeforeElement); 
                        break;
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:TextRangeEdit.cs

示例6: MoveToFirstNonCharacterSymbol

 // move to the first non-character symbol, but not pass beyond the limit
 private static void MoveToFirstNonCharacterSymbol(
     TextPointer navigator,   // navigator to move
     TextPointer  stopHint     // don't move further if we already pass beyond this point
     )         
 {
     while (navigator.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text 
         && navigator.CompareTo(stopHint) < 0
         && navigator.MoveToNextContextPosition(LogicalDirection.Forward)) ;
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:10,代码来源:TextEffectResolver.cs

示例7: MoveToFirstCharacterSymbol

 //---------------------------
 // Private static methods
 //---------------------------
 
 // move to the first character symbol
 private static void MoveToFirstCharacterSymbol(TextPointer navigator)
 {
     while (navigator.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.Text
         && navigator.MoveToNextContextPosition(LogicalDirection.Forward)) ;
 }
开发者ID:JianwenSun,项目名称:cc,代码行数:10,代码来源:TextEffectResolver.cs

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