New to Telerik UI for WPF? Download free 30-day trial

Text Position

TextPosition is a position in the text of a RadFixedDocument. They enable keeping track of a "current" position in the document (i.e. a caret) and lay the foundations of document selection.

Creation

One can create a TextPostion for a particular document, page and index using one of the constructors:

public TextPosition(RadFixedDocument document)  
public TextPosition(RadFixedPage page) 
public TextPosition(RadFixedPage page, int index)  
public TextPosition(TextPosition position) 

The constructors that accept a RadFixedPage as parameter create a TextPosition for the particular page.

The offset you specify will be the offset in the current page in terms of number of characters.

If you pass only the RadFixedDocument instance, a TextPosition for the first page will be created.

In case you want to make a copy of a TextPosition, you can opt for the constructor listed last.

Members

The members that the TextPosition class exposes are:

  • Properties:
    • Index - the integer offset of the text position into the page.
    • Page - the RadFixedPage that the position belongs to.
  • Methods:
    • TextPosition overrides the equality operator, so that you can compare positions in the document depending on their position using <, > and =.
    • The other methods of the class provide the means for navigation in the document and have self-explanatory names and arguments:

public bool MoveToNextPosition() 
public bool MoveToPreviousPosition() 
public bool MoveToPosition(TextPosition position) 
public bool MoveToNextWord() 
public bool MoveToPreviousWord() 
public bool MoveToCurrentWordStart() 
public bool MoveToCurrentWordEnd() 
public bool MoveToLineStart() 
public bool MoveToLineEnd() 
public bool MoveLineUp() 
public bool MoveLineDown() 
public bool MoveToStartOfDocument() 
public bool MoveToEndOfDocument() 
  • Events:
    • PositionChanging - occurs just before the position is moved;
    • PositionChanged - occurs after the position has moved.

The caret position of RadFixedDocument is also a TextPosition and all methods and properties listed above could be used with it as well. Here is an example:

this.pdfViewer.Document.CaretPosition.MoveToEndOfDocument(); 

This will not only move the caret to the end of the document, but will also scroll the document to bring it into view, as the view port follows the caret.

See Also

In this article