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


C# TextPointer.CompareTo方法代码示例

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


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

示例1: Resolve

        //---------------------------
        // public static methods
        //---------------------------
        
        /// <summary>
        /// resolves text effect on a text range to a list of text effect targets.
        /// The method will walk the text and perform the following task:
        /// 1) For each continous block of text, create a text effect targeting the scoping element
        /// 2) For the text effect created, calculate the starting cp index and cp count for the effect
        /// 
        /// The method will create freezable copy of the TextEffect passed in and fill in 
        /// CharacterIndex and Count for the range.
        /// </summary>
        /// <param name="startPosition">starting text pointer</param>
        /// <param name="endPosition">end text pointer</param>
        /// <param name="effect">effect that is apply on the text</param>
        public static TextEffectTarget[] Resolve(
            TextPointer             startPosition, 
            TextPointer             endPosition,
            TextEffect              effect
            )
        {
            if (effect == null)
                throw new ArgumentNullException("effect");

            ValidationHelper.VerifyPositionPair(startPosition, endPosition);            
            TextPointer   effectStart   = new TextPointer(startPosition);            

            // move to the first character symbol at or after Start position
            MoveToFirstCharacterSymbol(effectStart);

            TextEffect effectCopy;
            List<TextEffectTarget> list = new List<TextEffectTarget>();

            // we will now traverse the TOM and resolve text effects to the immediate parent 
            // of the characters. We are effectively applying the text effect onto 
            // block of continous text.
            while (effectStart.CompareTo(endPosition) < 0)
            {   
                // create a copy of the text effect 
                // so that we can set the CharacterIndex and Count
                effectCopy                 = effect.Clone();

                // create a position
                TextPointer continuousTextEnd = new TextPointer(effectStart);
                
                // move the position to the end of the continuous text block
                MoveToFirstNonCharacterSymbol(continuousTextEnd, endPosition);

                // make sure we are not out of the range
                continuousTextEnd = (TextPointer)TextPointerBase.Min(continuousTextEnd, endPosition);

                // set the character index to be the distance from the Start 
                // of this text block to the Start of the text container
                effectCopy.PositionStart = effectStart.TextContainer.Start.GetOffsetToPosition(effectStart);

                // count is the distance from the text block start to end
                effectCopy.PositionCount = effectStart.GetOffsetToPosition(continuousTextEnd);

                list.Add(
                    new TextEffectTarget(
                        effectStart.Parent, 
                        effectCopy
                        )
                 );
                
                // move the effectStart to the beginning of the next text block.
                effectStart = continuousTextEnd;
                MoveToFirstCharacterSymbol(effectStart);
            }

            return list.ToArray();
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:73,代码来源:TextEffectResolver.cs

示例2: Write

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

        //------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------

        //------------------------------------------------------
        //
        //  Protected Methods
        //
        //------------------------------------------------------

        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal methods.

        /// <summary>
        /// Writes the container into the specified XmlWriter.
        /// </summary>
        internal void Write(TextPointer start, TextPointer end, XmlWriter writer)
        {
            System.Diagnostics.Debug.Assert(start != null);
            System.Diagnostics.Debug.Assert(end != null);
            System.Diagnostics.Debug.Assert(start.CompareTo(end) <= 0);
            System.Diagnostics.Debug.Assert(writer != null);

            WriteContainer(start, end, writer);
        }
开发者ID:ClemensT,项目名称:WPF-Samples,代码行数:38,代码来源:wordxmlwriter.cs

示例3: GetCharOffsetToPosition

        private static int GetCharOffsetToPosition(InlineCollection inlineCollection, TextPointer position, out TextPointer result)
        {
            int offset = 0;
            foreach (var inline in inlineCollection)
            {
                offset += GetCharOffsetToPosition(inline, position, out result);
                if (result == null || result.CompareTo(position) >= 0)
                    return offset;
            }

            result = null;
            return offset;
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:13,代码来源:FlowDocumentExtensions.cs

示例4: GetCharacterRects

        internal override Rect[] GetCharacterRects(TextPointer startPointer, TextPointer endPointer)
        {
            if (!invalidatedCache && cachedStartP != null && startPointer.CompareTo(cachedStartP) == 0)
            {
                return cachedRects;
            }
            else
            {
                cachedRects = base.GetCharacterRects(startPointer, endPointer);
                cachedStartP = startPointer;
                invalidatedCache = false;
            }

            return cachedRects;
        }
开发者ID:vearvindkumar,项目名称:Scrapper,代码行数:15,代码来源:RichTextBoxHighlightAdorner.cs

示例5: CreateDeleteContentUndoUnit

        // Adds a DeleteContentUndoUnit to the open parent undo unit, if any.
        // Called by TextContainer.DeleteContent.
        internal static TextTreeDeleteContentUndoUnit CreateDeleteContentUndoUnit(TextContainer tree, TextPointer start, TextPointer end)
        {
            UndoManager undoManager;
            TextTreeDeleteContentUndoUnit undoUnit;

            if (start.CompareTo(end) == 0)
                return null;

            undoManager = GetOrClearUndoManager(tree);
            if (undoManager == null)
                return null;

            undoUnit = new TextTreeDeleteContentUndoUnit(tree, start, end);

            undoManager.Add(undoUnit);

            return undoUnit;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:20,代码来源:TextTreeUndo.cs

示例6: 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

示例7: FindNext

      /// <summary>
      /// Find the input string within the document, starting at the specified position.
      /// </summary>
      /// <param name="position">the current text position</param>
      /// <param name="input">input text</param>
      /// <returns>An <see cref="TextRange"/> representing the (next) matching string within the text container. Null if there are no matches.</returns>
      public TextRange FindNext(ref TextPointer position, String input)
      {
         FindText(input);

         foreach (var result in _searchHits)
         {
            if (position.CompareTo(result.End) < 0)
            {
               position = result.Start;
               double top = this.PointToScreen(position.GetLineStartPosition(0).GetCharacterRect(LogicalDirection.Forward).TopLeft).Y + this.PointFromScreen(new System.Windows.Point(0, 0)).Y;
               Trace.WriteLine(string.Format(" Top: {0}, CharOffset: {1}", top, position));
               ScrollViewer.ScrollToVerticalOffset(ScrollViewer.VerticalOffset + top);
               position = result.End;
               return result;
            }
         }
         return null;
      }
开发者ID:ForNeVeR,项目名称:PoshConsole,代码行数:24,代码来源:ConsoleControl.cs

示例8: DeleteContent

        /// <summary>
        /// Makes sure that the content spanned by the range is totally deleted 
        /// including all structural elements and boundaries.
        /// We need this method to be able to make the range empty for any kind of content. 
        /// This operation is straightforward for all kinds of ranges expect for 
        /// TableCellRange. For cell range it means merging all selected cells
        /// and deleting the text content of resulting cell. 
        /// </summary>
        internal static void DeleteContent(TextPointer start, TextPointer end)
        {
            // Order positions, as we do not to distinguish between anchor/moving ends in this operation; 
            // but the following code depends on start<=end ordering
            if (start.CompareTo(end) > 0) 
            { 
                TextPointer whatWasEnd = end;
                end = start; 
                start = whatWasEnd;
            }

            // Check whether we cross table structure boundaries 
            TableCell startCell;
            TableCell endCell; 
            TableRow startRow; 
            TableRow endRow;
            TableRowGroup startRowGroup; 
            TableRowGroup endRowGroup;
            Table startTable;
            Table endTable;
 
            // We need to run a loop here because after boundary tables deletions
            // we may encounter following tables, so that start/end range will be 
            // again table-crossing. 
            while (
                start.CompareTo(end) < 0 
                &&
                IdentifyTableElements(
                    /*anchorPosition:*/start, /*movingPosition:*/end,
                    /*includeCellAtMovingPosition:*/false, 
                    out startCell, out endCell,
                    out startRow, out endRow, 
                    out startRowGroup, out endRowGroup, 
                    out startTable, out endTable))
            { 
                if (startTable == null && endTable == null || startTable == endTable)
                {
                    bool isTableCellRange;
                    List<TextSegment> textSegments = TextRangeEditTables.BuildTableRange( 
                        /*anchorPosition:*/start,
                        /*movingPosition:*/end, 
                        /*includeCellAtMovingPosition*/false, 
                        out isTableCellRange);
 
                    if (isTableCellRange && textSegments != null)
                    {
                        // It is cell selection. Create the content of all selected cells
                        for (int i = 0; i < textSegments.Count; i++) 
                        {
                            ClearTableCells(textSegments[i]); 
                        } 
                        // Collapse the range to bypass the folowing paragraph deletion
                        end = start; 
                    }
                    else
                    {
                        // Our range is within one table, so we need to delete 
                        // crossed row boundaries
 
                        // Find start row 
                        if (startCell != null)
                        { 
                            startRow = startCell.Row;
                        }
                        else if (startRow != null)
                        { 
                            // do nothing here. we already have a start row for deletion.
                        } 
                        else if (startRowGroup != null) 
                        {
                            startRow = startRowGroup.Rows[0]; 
                        }

                        // Find end row
                        if (endCell != null) 
                        {
                            endRow = startCell.Row; 
                        } 
                        else if (endRow != null)
                        { 
                            // do nothing here. we already have an end row for deletion.
                        }
                        else if (endRowGroup != null)
                        { 
                            endRow = endRowGroup.Rows[endRowGroup.Rows.Count - 1];
                        } 
 
                        Invariant.Assert(startRow != null && endRow != null, "startRow and endRow cannot be null, since our range is within one table");
                        TextRange rowsSegment = new TextRange(startRow.ContentStart, endRow.ContentEnd); 
                        TextRangeEditTables.DeleteRows(rowsSegment); // it will take care of rowspans
                    }
                }
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:TextRangeEditTables.cs

示例9: Span

        /// <summary>
        /// Creates a new Span instance covering existing content.
        /// </summary>
        /// <param name="start">
        /// Start position of the new Span.
        /// </param>
        /// <param name="end">
        /// End position of the new Span.
        /// </param>
        /// <remarks>
        /// start and end must both be parented by the same Paragraph, otherwise
        /// the method will raise an ArgumentException.
        /// </remarks>
        public Span(TextPointer start, TextPointer end)
        {
            if (start == null)
            {
                throw new ArgumentNullException("start");
            }
            if (end == null)
            {
                throw new ArgumentNullException("start");
            }
            if (start.TextContainer != end.TextContainer)
            {
                throw new ArgumentException(SR.Get(SRID.InDifferentTextContainers, "start", "end"));
            }
            if (start.CompareTo(end) > 0)
            {
                throw new ArgumentException(SR.Get(SRID.BadTextPositionOrder, "start", "end"));
            }

            start.TextContainer.BeginChange();
            try
            {
                start = TextRangeEditTables.EnsureInsertionPosition(start);
                Invariant.Assert(start.Parent is Run);
                end = TextRangeEditTables.EnsureInsertionPosition(end);
                Invariant.Assert(end.Parent is Run);

                if (start.Paragraph != end.Paragraph)
                {
                    throw new ArgumentException(SR.Get(SRID.InDifferentParagraphs, "start", "end"));
                }

                // If start or end positions have a Hyperlink ancestor, we cannot split them.
                Inline nonMergeableAncestor;
                if ((nonMergeableAncestor = start.GetNonMergeableInlineAncestor()) != null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.TextSchema_CannotSplitElement, nonMergeableAncestor.GetType().Name));
                }
                if ((nonMergeableAncestor = end.GetNonMergeableInlineAncestor()) != null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.TextSchema_CannotSplitElement, nonMergeableAncestor.GetType().Name));
                }

                TextElement commonAncestor = TextElement.GetCommonAncestor((TextElement)start.Parent, (TextElement)end.Parent);

                while (start.Parent != commonAncestor)
                {
                    start = SplitElement(start);
                }
                while (end.Parent != commonAncestor)
                {
                    end = SplitElement(end);
                }

                if (start.Parent is Run)
                {
                    start = SplitElement(start);
                }
                if (end.Parent is Run)
                {
                    end = SplitElement(end);
                }

                Invariant.Assert(start.Parent == end.Parent);
                Invariant.Assert(TextSchema.IsValidChild(/*position*/start, /*childType*/typeof(Span)));

                this.Reposition(start, end);
            }
            finally
            {
                start.TextContainer.EndChange();
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:86,代码来源:Span.cs

示例10: ApplyContextualProperty

        // Applies one property to a range from start to end to simulate inheritance of this property from source conntext
        private static void ApplyContextualProperty(Type targetType, TextPointer start, TextPointer end, DependencyProperty property, object value)
        {
            if (TextSchema.ValuesAreEqual(start.Parent.GetValue(property), value))
            {
                return; // The property at insertion position is the same as it was in source context. Nothing to do.
            }
            
            // Advance start pointer to enter pasted fragment
            start = start.GetNextContextPosition(LogicalDirection.Forward);

            while (start != null && start.CompareTo(end) < 0)
            {
                TextPointerContext passedContext = start.GetPointerContext(LogicalDirection.Backward);
                if (passedContext == TextPointerContext.ElementStart)
                {
                    TextElement element = (TextElement)start.Parent;

                    // Check if this element affects the property in question
                    if (element.ReadLocalValue(property) != DependencyProperty.UnsetValue ||
                        !TextSchema.ValuesAreEqual(element.GetValue(property), element.Parent.GetValue(property)))
                    {
                        // The element affects this property, so we can skip it
                        start = element.ElementEnd;
                    }
                    else if (targetType.IsAssignableFrom(element.GetType()))
                    {
                        start = element.ElementEnd;

                        if (targetType == typeof(Block) && start.CompareTo(end) > 0)
                        {
                            // Contextual properties should not apply to the last paragraph
                            // when it is merged with the following content -
                            // to avoid affecting the folowing visible content formatting.
                            break;
                        }

                        // This is topmost-level inline element which inherits this property.
                        // Set the value explicitly
                        if (!TextSchema.ValuesAreEqual(value, element.GetValue(property)))
                        {
                            element.ClearValue(property);
                            if (!TextSchema.ValuesAreEqual(value, element.GetValue(property)))
                            {
                                element.SetValue(property, value);
                            }

                            TextRangeEdit.MergeFormattingInlines(element.ElementStart);
                        }
                    }
                    else
                    {
                        // Traverse down into a structured (non-innline) element
                        start = start.GetNextContextPosition(LogicalDirection.Forward);
                    }
                }
                else
                {
                    // Traverse up from any element
                    Invariant.Assert(passedContext != TextPointerContext.None, "TextPointerContext.None is not expected");
                    start = start.GetNextContextPosition(LogicalDirection.Forward);
                }
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:64,代码来源:TextRangeSerialization.cs

示例11: GetTextRangeFromPosition

        /// <summary>
        /// Find the corresponding <see cref="TextRange"/> instance 
        /// representing the input string given a specified text pointer position.
        /// </summary>
        /// <param name="position">the current text position</param>
        /// <param name="textToFind">input text</param>
        /// <param name="findOptions">the search option</param>
        /// <returns>An <see cref="TextRange"/> instance represeneting the matching string withing the text container.</returns>
        public TextRange GetTextRangeFromPosition(ref TextPointer position, String input, FindOptions findOptions)
        {
            Boolean matchCase = findOptions.MatchCase;
            Boolean matchWholeWord = findOptions.MatchWholeWord;

            TextRange textRange = null;

            while (position != null)
            {
                if (position.CompareTo(inputDocument.ContentEnd) == 0) //到了文档结尾
                {
                    break;
                }
                //是文本元素
                if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
                {
                    String textRun = position.GetTextInRun(LogicalDirection.Forward);  //读取文本
                    StringComparison stringComparison = matchCase ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
                  //进行查找
                    Int32 indexInRun = textRun.IndexOf(input, stringComparison);

                    if (indexInRun >= 0)  //找到了
                    {
                        position = position.GetPositionAtOffset(indexInRun);  //移动文字指针到开头
                        TextPointer nextPointer = position.GetPositionAtOffset(input.Length); //设定匹配项尾文字指针
                        textRange = new TextRange(position, nextPointer);

                        if (matchWholeWord) //是全字匹配的话
                        {
                            if (IsWholeWord(textRange)) // 测试匹配项是否是一个单词
                            {
                                // 是一个完整的单词
                                break;
                            }
                            else
                            {
                                // 找到的不是一个完整的单词,继续在本Run元素中查找
                                position = position.GetPositionAtOffset(input.Length);
                                return GetTextRangeFromPosition(ref position, input, findOptions);
                            }
                        }
                        else
                        {
                            //不要求全字匹配
                            position = position.GetPositionAtOffset(input.Length);
                            break;
                        }
                    }
                    else
                    {
                        // 没找到匹配项,移到当前的Run元素之后 "textRun".
                        position = position.GetPositionAtOffset(textRun.Length);
                    }
                }
                else
                {
                    //如果当前位置不是文本类型的元素,继续"前进",跳过这些非文本元素.
                    position = position.GetNextContextPosition(LogicalDirection.Forward);
                }
            }

            return textRange;
        }
开发者ID:puma007,项目名称:PersonalInfoForWPF,代码行数:71,代码来源:FindAndReplaceManager.cs

示例12: ApplyStructuralInlinePropertyAcrossRun

        private static void ApplyStructuralInlinePropertyAcrossRun(TextPointer start, TextPointer end, Run run, DependencyProperty formattingProperty, object value)
        { 
            if (start.CompareTo(end) == 0)
            {
                // When the range is empty we should ignore the command, except
                // for the case of empty Run which can be encountered in empty paragraphs 
                if (run.IsEmpty)
                { 
                    run.SetValue(formattingProperty, value); 
                }
            } 
            else
            {
                // Split elements at start and end boundaries.
                start = SplitFormattingElements(start, /*keepEmptyFormatting:*/false, /*limitingAncestor*/run.Parent as TextElement); 
                end = SplitFormattingElements(end, /*keepEmptyFormatting:*/false, /*limitingAncestor*/run.Parent as TextElement);
 
                run = (Run)start.GetAdjacentElement(LogicalDirection.Forward); 
                run.SetValue(formattingProperty, value);
            } 

            // Clear property value from all ancestors of this Run.
            FixupStructuralPropertyEnvironment(run, formattingProperty);
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:24,代码来源:TextRangeEdit.cs

示例13: ValidateMergingPositions

        // Validates that the sibling element at this position belong to expected itemType (Inline, Block, ListItem)
        private static void ValidateMergingPositions(Type itemType, TextPointer start, TextPointer end)
        {
            if (start.CompareTo(end) < 0)
            {
                // Verify inner part
                TextPointerContext forwardFromStart = start.GetPointerContext(LogicalDirection.Forward);
                TextPointerContext backwardFromEnd = end.GetPointerContext(LogicalDirection.Backward);
                Invariant.Assert(forwardFromStart == TextPointerContext.ElementStart, "Expecting first opening tag of pasted fragment");
                Invariant.Assert(backwardFromEnd == TextPointerContext.ElementEnd, "Expecting last closing tag of pasted fragment");
                Invariant.Assert(itemType.IsAssignableFrom(start.GetAdjacentElement(LogicalDirection.Forward).GetType()), "The first pasted fragment item is expected to be a " + itemType.Name);
                Invariant.Assert(itemType.IsAssignableFrom(end.GetAdjacentElement(LogicalDirection.Backward).GetType()), "The last pasted fragment item is expected to be a " + itemType.Name);

                // Veryfy outer part
                TextPointerContext backwardFromStart = start.GetPointerContext(LogicalDirection.Backward);
                TextPointerContext forwardFromEnd = end.GetPointerContext(LogicalDirection.Forward);
                Invariant.Assert(backwardFromStart == TextPointerContext.ElementStart || backwardFromStart == TextPointerContext.ElementEnd || backwardFromStart == TextPointerContext.None, "Bad context preceding a pasted fragment");
                Invariant.Assert(!(backwardFromStart == TextPointerContext.ElementEnd) || itemType.IsAssignableFrom(start.GetAdjacentElement(LogicalDirection.Backward).GetType()), "An element preceding a pasted fragment is expected to be a " + itemType.Name);
                Invariant.Assert(forwardFromEnd == TextPointerContext.ElementStart || forwardFromEnd == TextPointerContext.ElementEnd || forwardFromEnd == TextPointerContext.None, "Bad context following a pasted fragment");
                Invariant.Assert(!(forwardFromEnd == TextPointerContext.ElementStart) || itemType.IsAssignableFrom(end.GetAdjacentElement(LogicalDirection.Forward).GetType()), "An element following a pasted fragment is expected to be a " + itemType.Name);
            }
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:22,代码来源:TextRangeSerialization.cs

示例14: GetNextRun

        // Finds a Run element with ElementStart at or after the given pointer
        // Creates Runs at potential run positions if encounters some. 
        private static Run GetNextRun(TextPointer pointer, TextPointer limit) 
        {
            Run run = null; 

            while (pointer != null && pointer.CompareTo(limit) < 0)
            {
                if (pointer.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementStart && 
                    (run = pointer.GetAdjacentElement(LogicalDirection.Forward) as Run) != null)
                { 
                    break; 
                }
 
                if (TextPointerBase.IsAtPotentialRunPosition(pointer))
                {
                    pointer = TextRangeEditTables.EnsureInsertionPosition(pointer);
                    Invariant.Assert(pointer.Parent is Run); 
                    run = pointer.Parent as Run;
                    break; 
                } 

                // Advance the scanning pointer 
                pointer = pointer.GetNextContextPosition(LogicalDirection.Forward);
            }

            return run; 
        }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:28,代码来源:TextRangeEdit.cs

示例15: ClearPropertyValueFromSpansAndRuns

        // Helper that walks Run and Span elements between start and end positions, 
        // clearing value of passed formattingProperty on them.
        // 
        private static void ClearPropertyValueFromSpansAndRuns(TextPointer start, TextPointer end, DependencyProperty formattingProperty)
        {
            // Normalize start position forward.
            start = start.GetPositionAtOffset(0, LogicalDirection.Forward); 

            // Move to next context position before entering loop below, 
            // since in the loop we look backward. 
            start = start.GetNextContextPosition(LogicalDirection.Forward);
 
            while (start != null && start.CompareTo(end) < 0)
            {
                if (start.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart &&
                    TextSchema.IsFormattingType(start.Parent.GetType())) // look for Run/Span elements 
                {
                    start.Parent.ClearValue(formattingProperty); 
 
                    // Remove unnecessary Spans around this position, delete empty formatting elements (if any)
                    // and merge with adjacent inlines if they have identical set of formatting properties. 
                    MergeFormattingInlines(start);
                }

                start = start.GetNextContextPosition(LogicalDirection.Forward); 
            }
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:27,代码来源:TextRangeEdit.cs


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