TextPointer.IsInSameDocument(TextPointer) TextPointer.IsInSameDocument(TextPointer) TextPointer.IsInSameDocument(TextPointer) TextPointer.IsInSameDocument(TextPointer) Method

Definición

Indica si la posición especificada está en el mismo contenedor de texto que la posición actual.Indicates whether the specified position is in the same text container as the current position.

public:
 bool IsInSameDocument(System::Windows::Documents::TextPointer ^ textPosition);
public bool IsInSameDocument (System.Windows.Documents.TextPointer textPosition);
member this.IsInSameDocument : System.Windows.Documents.TextPointer -> bool
Public Function IsInSameDocument (textPosition As TextPointer) As Boolean

Parámetros

textPosition
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

true si textPosition indica una posición que está en el mismo contenedor de texto que la posición actual; de lo contrario, false.true if textPosition indicates a position that is in the same text container as the current position; otherwise, false.

Excepciones

El valor de textPosition es null.textPosition is null.

Ejemplos

El ejemplo siguiente muestra un uso de este método.The following example demonstrates a use for this method. El ejemplo se usa el IsInSameDocument método para comprobar si un TextPointer se sitúa entre dos otros especificado TextPointer instancias en una situación cuando no hay ninguna garantía de que las tres posiciones pertenezcan al mismo contenedor de texto.The example uses the IsInSameDocument method to check whether a specified TextPointer is positioned between two other specified TextPointer instances in a situation when there is no guarantee that all three positions belong to the same text container.

// This method first checks for compatible text container scope, and then checks whether
// a specified position is between two other specified positions.
bool IsPositionContainedBetween(TextPointer positionToTest, TextPointer start, TextPointer end)
{
    // Note that without this check, an exception will be raised by CompareTo if positionToTest 
    // does not point to a position that is in the same text container used by start and end.
    //
    // This test also implicitely indicates whether start and end share a common text container.
    if (!positionToTest.IsInSameDocument(start) || !positionToTest.IsInSameDocument(end)) 
        return false;
    
    return start.CompareTo(positionToTest) <= 0 && positionToTest.CompareTo(end) <= 0;
}
' This method first checks for compatible text container scope, and then checks whether
' a specified position is between two other specified positions.
Private Function IsPositionContainedBetween(ByVal positionToTest As TextPointer, ByVal start As TextPointer, ByVal [end] As TextPointer) As Boolean
    ' Note that without this check, an exception will be raised by CompareTo if positionToTest 
    ' does not point to a position that is in the same text container used by start and end.
    '
    ' This test also implicitely indicates whether start and end share a common text container.
    If (Not positionToTest.IsInSameDocument(start)) OrElse (Not positionToTest.IsInSameDocument([end])) Then
        Return False
    End If

    Return start.CompareTo(positionToTest) <= 0 AndAlso positionToTest.CompareTo([end]) <= 0
End Function

Comentarios

La mayoría de las operaciones que implican varios TextPointer instancias solo son válidas si las instancias en cuestión indican posiciones que se encuentran en el mismo ámbito contenedor de texto.Most operations that involve multiple TextPointer instances are only valid if the instances in question indicate positions that are in the same text container scope. Por ejemplo el CompareTo y GetOffsetToPosition métodos no se puede usar con un TextPointer a una posición fuera del contenedor de texto asociado a la posición actual.For example the CompareTo and GetOffsetToPosition methods cannot be used with a TextPointer to a position outside of the text container associated with the current position. Use este método para comprobar que un determinado TextPointer es compatible con la posición actual para estas operaciones.Use this method to verify that a specified TextPointer is compatible with the current position for such operations.

Se aplica a