TextPointer.CompareTo(TextPointer) TextPointer.CompareTo(TextPointer) TextPointer.CompareTo(TextPointer) TextPointer.CompareTo(TextPointer) Method

Definición

Realiza una comparación de ordinales entre las posiciones especificadas por el TextPointer actual y un segundo TextPointer especificado.Performs an ordinal comparison between the positions specified by the current TextPointer and a second specified TextPointer.

public:
 int CompareTo(System::Windows::Documents::TextPointer ^ position);
public int CompareTo (System.Windows.Documents.TextPointer position);
member this.CompareTo : System.Windows.Documents.TextPointer -> int
Public Function CompareTo (position As TextPointer) As Integer

Parámetros

position
TextPointer TextPointer TextPointer TextPointer

TextPointer que especifica una posición para comparar a la posición actual.A TextPointer that specifies a position to compare to the current position.

Devoluciones

-1 si el TextPointer actual precede a position; 0 si las ubicaciones son las mismas; +1 si el TextPointer actual sigue a position.-1 if the current TextPointer precedes position; 0 if the locations are the same; +1 if the current TextPointer follows position.

Excepciones

position especifica una posición fuera del contenedor de texto asociado a la posición actual.position specifies a position outside of the text container associated with the current position.

Ejemplos

El ejemplo siguiente muestra un uso de este método.The following example demonstrates a use for this method. En el ejemplo, el CompareTo método se utiliza junto con el GetInsertionPosition método para comprobar si un determinado TextElement está vacío.In the example, the CompareTo method is used in conjunction with the GetInsertionPosition method to test whether a specified TextElement is empty.

// Tests to see if the specified TextElement is empty (has no printatble content).
bool IsElementEmpty(TextElement element)
{
    // Find starting and ending insertion positions in the element.
    // Inward-facing directions are used to make sure that insertion position
    // will be found correctly in case when the element may contain inline 
    // formatting elements (such as a Span or Run that contains Bold or Italic elements).
    TextPointer start = element.ContentStart.GetInsertionPosition(LogicalDirection.Forward);
    TextPointer end = element.ContentEnd.GetInsertionPosition(LogicalDirection.Backward);
     
    // The element has no printable content if its first and last insertion positions are equal.
    return start.CompareTo(end) == 0;

} // End IsEmptyElement method.
' Tests to see if the specified TextElement is empty (has no printatble content).
Private Function IsElementEmpty(ByVal element As TextElement) As Boolean
    ' Find starting and ending insertion positions in the element.
    ' Inward-facing directions are used to make sure that insertion position
    ' will be found correctly in case when the element may contain inline 
    ' formatting elements (such as a Span or Run that contains Bold or Italic elements).
    Dim start As TextPointer = element.ContentStart.GetInsertionPosition(LogicalDirection.Forward)
    Dim [end] As TextPointer = element.ContentEnd.GetInsertionPosition(LogicalDirection.Backward)

    ' The element has no printable content if its first and last insertion positions are equal.
    Return start.CompareTo([end]) = 0

End Function ' End IsEmptyElement method.

Comentarios

Un valor de -1 indica que la posición especificada por el actual TextPointer precede a la posición especificada por position.A value of -1 indicates that the position specified by the current TextPointer precedes the position specified by position. Un valor de 0 indica que las posiciones indicadas son iguales.A value of 0 indicates that the indicated positions are equal. Un valor de + 1 positivo indica que la posición especificada por el actual TextPointer sigue a la posición especificada por position.A value of positive +1 indicates that the position specified by the current TextPointer follows the position specified by position.

Se aplica a

Consulte también: