TextPointer.IsInSameDocument(TextPointer) Metoda

Definice

Určuje, zda je zadaná pozice ve stejném textovém kontejneru jako aktuální pozice.

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

Parametry

textPosition
TextPointer

Určuje TextPointer pozici, která se má porovnat s aktuální pozicí.

Návraty

true pokud textPosition označuje pozici, která je ve stejném textovém kontejneru jako aktuální pozice; falsev opačném případě .

Výjimky

textPosition je null.

Příklady

Následující příklad ukazuje použití pro tuto metodu. Příklad používá metodu IsInSameDocument ke kontrole, zda je zadaná TextPointer pozice umístěna mezi dvěma dalšími zadanými TextPointer instancemi v situaci, kdy neexistuje žádná záruka, že všechny tři pozice patří do stejného textového kontejneru.

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

Poznámky

Většina operací zahrnujících více TextPointer instancí je platná pouze v případě, že příslušné instance označují pozice, které jsou ve stejném oboru kontejneru textu. Například CompareTo metody a GetOffsetToPosition metody nelze použít s TextPointer umístěním mimo textový kontejner přidružený k aktuální pozici. Tuto metodu použijte k ověření kompatibility zadaného TextPointer stavu s aktuální pozicí pro tyto operace.

Platí pro