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


C# TextRange.SelectParagraph方法代码示例

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


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

示例1: OnMoveUpByParagraph

        private static void OnMoveUpByParagraph(object sender, ExecutedRoutedEventArgs args)
        {
            TextEditor This = TextEditor._GetTextEditor(sender);

            if (This == null || !This._IsEnabled || !This._IsSourceInScope(args.Source))
            {
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);

            using (This.Selection.DeclareChangeBlock())
            {
                // Forget previously suggested horizontal position
                TextEditorSelection._ClearSuggestedX(This);

                // Discard typing undo unit merging
                TextEditorTyping._BreakTypingSequence(This);

                // Clear springload formatting
                ClearSpringloadFormatting(This);

                // Move/extend selection in requested direction
                if (!This.Selection.IsEmpty)
                {
                    // If the selection is non-empty and ends on a word boundary, collapse it to that boundary.
                    // Collapsing must happen to selection START - not to its moving position.
                    // It is Word behavior for setting a cratet on moving down from nonempty selection.
                    ITextPointer position = TextEditorSelection.GetStartInner(This);

                    This.Selection.SetCaretToPosition(position, position.LogicalDirection, /*allowStopAtLineEnd:*/false, /*allowStopNearSpace:*/false);
                }
                ITextPointer movingPointer = This.Selection.MovingPosition.CreatePointer();
                ITextRange paragraphRange = new TextRange(movingPointer, movingPointer);
                paragraphRange.SelectParagraph(movingPointer);

                if (This.Selection.Start.CompareTo(paragraphRange.Start) > 0)
                {
                    // We are in the middle of a paragraph. Move to its start
                    This.Selection.SetCaretToPosition(paragraphRange.Start, LogicalDirection.Backward, /*allowStopAtLineEnd:*/false, /*allowStopNearSpace:*/false);
                }
                else
                {
                    movingPointer.MoveToPosition(paragraphRange.Start);
                    if (movingPointer.MoveToNextInsertionPosition(LogicalDirection.Backward))
                    {
                        // Previous paragraph found. Set selection to its start
                        paragraphRange.SelectParagraph(movingPointer);
                        This.Selection.SetCaretToPosition(paragraphRange.Start, LogicalDirection.Backward, /*allowStopAtLineEnd:*/false, /*allowStopNearSpace:*/false);
                    }
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:53,代码来源:TextEditorSelection.cs

示例2: MovePositionByUnits


//.........这里部分代码省略.........

                    break;

                case TextUnit.Line:
                    // Position is snapped to nearest line boundary. But since line information
                    // is based on the layout, position is not changed, if:
                    // a) it is not currently in the view, or
                    // b) containing line cannot be found.
                    textView = _textAdaptor.GetUpdatedTextView();
                    if (textView != null && textView.IsValid && textView.Contains(position))
                    {
                        // ITextPointer.MoveToLineBoundary can't handle Table row end positions.
                        // Mimic TextEditor's caret navigation code and move into the preceding
                        // TableCell.
                        if (TextPointerBase.IsAtRowEnd(position))
                        {
                            position.MoveToNextInsertionPosition(LogicalDirection.Backward);
                        }

                        moved = position.MoveToLineBoundary(count);
                        
                        MoveToInsertionPosition(position, LogicalDirection.Forward);

                        if (moved < 0)
                        {
                            moved = -moved; // Will be reversed below.
                        }
                    }
                    break; 

                case TextUnit.Paragraph:
                    // Utilize TextRange logic to determine paragraph boundaries.
                    ITextRange paragraphRange = new TextRange(position, position);
                    paragraphRange.SelectParagraph(position);
                    while (moved < absCount)
                    {
                        position.MoveToPosition(direction == LogicalDirection.Forward ? paragraphRange.End : paragraphRange.Start);
                        if (!position.MoveToNextInsertionPosition(direction))
                        {
                            break;
                        }
                        moved++;
                        paragraphRange.SelectParagraph(position);
                        position.MoveToPosition(paragraphRange.Start); // Position it always at the beginning of the paragraph.
                    }
                    break;

                case TextUnit.Page:
                    // But since page information is based on the layout, position is not changed, if:
                    // a) it is not currently in the view, or
                    // b) containing page cannot be found.
                    // Page movement is possible only in multi-page scenario.
                    textView = _textAdaptor.GetUpdatedTextView();
                    if (textView != null && textView.IsValid && textView.Contains(position))
                    {
                        if (textView is MultiPageTextView)
                        {
                            // Get embedded page ITextView for given position.
                            ITextView pageTextView = ((MultiPageTextView)textView).GetPageTextViewFromPosition(position);
                            ReadOnlyCollection<TextSegment> textSegments = pageTextView.TextSegments;
                            while (moved < absCount)
                            {
                                if (textSegments == null || textSegments.Count == 0)
                                {
                                    break;
                                }
开发者ID:JianwenSun,项目名称:cc,代码行数:67,代码来源:TextRangeAdaptor.cs

示例3: OnSelectUpByParagraph

        private static void OnSelectUpByParagraph(object sender, ExecutedRoutedEventArgs args)
        {
            TextEditor This = TextEditor._GetTextEditor(sender);

            if (This == null || !This._IsEnabled || !This._IsSourceInScope(args.Source))
            {
                return;
            }

            TextEditorTyping._FlushPendingInputItems(This);

            using (This.Selection.DeclareChangeBlock())
            {
                // Forget previously suggested horizontal position
                TextEditorSelection._ClearSuggestedX(This);

                // Discard typing undo unit merging
                TextEditorTyping._BreakTypingSequence(This);

                // Clear springload formatting
                ClearSpringloadFormatting(This);

                ITextPointer movingPointer = This.Selection.MovingPosition.CreatePointer();
                ITextRange paragraphRange = new TextRange(movingPointer, movingPointer);
                paragraphRange.SelectParagraph(movingPointer);

                if (movingPointer.CompareTo(paragraphRange.Start) > 0)
                {
                    // We are in the middle of a paragraph. Move to its start
                    ExtendSelectionAndBringIntoView(paragraphRange.Start, This);
                }
                else
                {
                    movingPointer.MoveToPosition(paragraphRange.Start);
                    if (movingPointer.MoveToNextInsertionPosition(LogicalDirection.Backward))
                    {
                        // Previous paragraph found. Set selection to its start
                        paragraphRange.SelectParagraph(movingPointer);
                        ExtendSelectionAndBringIntoView(paragraphRange.Start, This);
                    }
                }
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:43,代码来源:TextEditorSelection.cs


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