Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TextPointer.CompareTo Method

July 28, 2014

Performs an ordinal comparison between the positions specified by the current TextPointer and a second specified TextPointer.

Namespace:  System.Windows.Documents
Assembly:  System.Windows (in System.Windows.dll)

public int CompareTo(
	TextPointer position
)

Parameters

position
Type: System.Windows.Documents.TextPointer
A TextPointer that specifies a position to compare to the current position.

Return Value

Type: System.Int32
-1 if the current TextPointer precedes position; 0 if the locations are the same; +1 if the current TextPointer follows positions.

ExceptionCondition
ArgumentException

position specifies a position from a different RichTextBox associated with the current position.

The following code uses the CompareTo method to find out if the RichTextBox is empty. This code example is part of a larger example used in the TextPointer class.


//This method returns true if the RichTextBox is empty.
public bool isRichTextBoxEmpty()
{
    TextPointer startPointer = MyRTB1.ContentStart.GetNextInsertionPosition(LogicalDirection.Forward);
    TextPointer endPointer = MyRTB1.ContentEnd.GetNextInsertionPosition(LogicalDirection.Backward);
    if (startPointer.CompareTo(endPointer) == 0)
        return true;
    else
        return false;
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2014 Microsoft