TextPointer.IsInSameDocument(TextPointer) Méthode

Définition

Indique si la position spécifiée est dans le même conteneur de texte que la position actuelle.

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

Paramètres

textPosition
TextPointer

Un TextPointer qui spécifie une position à comparer à la position actuelle.

Retours

Boolean

true si textPosition indique une position qui est dans le même conteneur de texte que la position actuelle ; sinon, false.

Exceptions

textPosition a la valeur null.

Exemples

L’exemple suivant illustre une utilisation pour cette méthode. L’exemple utilise la IsInSameDocument méthode pour vérifier si un spécifié TextPointer est positionné entre deux autres instances spécifiées TextPointer dans une situation où il n’existe aucune garantie que les trois positions appartiennent au même conteneur de texte.

// 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

Remarques

La plupart des opérations impliquant plusieurs TextPointer instances ne sont valides que si les instances en question indiquent des positions qui se trouvent dans la même étendue de conteneur de texte. Par exemple, les CompareTo méthodes et GetOffsetToPosition les méthodes ne peuvent pas être utilisées avec une TextPointer position en dehors du conteneur de texte associé à la position actuelle. Utilisez cette méthode pour vérifier qu’un spécifié TextPointer est compatible avec la position actuelle de ces opérations.

S’applique à