TextPointer.IsInSameDocument(TextPointer) Metódus

Definíció

Azt jelzi, hogy a megadott pozíció ugyanabban a szövegtárolóban van-e, mint az aktuális pozíció.

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éterek

textPosition
TextPointer

Az TextPointer aktuális pozícióhoz viszonyítandó pozíciót meghatározó beállítás.

Válaszok

trueha textPosition olyan pozíciót jelöl, amely ugyanabban a szövegtárolóban van, mint az aktuális pozíció; ellenkező esetben. false

Kivételek

textPosition az null.

Példák

Az alábbi példa a metódus használatát mutatja be. A példa a IsInSameDocument metódussal ellenőrzi, hogy a megadott TextPointer hely két másik megadott TextPointer példány között van-e olyan helyzetben, amikor nincs garancia arra, hogy mindhárom pozíció ugyanahhoz a szövegtárolóhoz tartozik.

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

Megjegyzések

A több TextPointer példányt tartalmazó műveletek többsége csak akkor érvényes, ha a szóban forgó példányok ugyanabban a szövegtároló-hatókörben lévő pozíciókat jelölnek. A metódusok és CompareTo a GetOffsetToPosition metódusok például nem használhatók TextPointer az aktuális pozícióhoz társított szövegtárolón kívüli helyre. Ezzel a módszerrel ellenőrizheti, hogy egy megadott TextPointer kompatibilis-e az ilyen műveletek jelenlegi helyzetével.

A következőre érvényes: