本文整理汇总了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);
}
}
}
}
示例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;
}
示例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);
}
}
}
}