共用方式為


TextPointer.IsInSameDocument(TextPointer) 方法

定義

表示指定的位置是否與目前位置位於相同的文字容器中。

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

參數

textPosition
TextPointer

TextPointer,指定要與目前位置進行比較的位置。

傳回

如果 textPosition 指出與目前位置位於相同文字容器的位置則為 true,否則為 false

例外狀況

textPositionnull

範例

下列範例示範這個方法的用法。 此範例會 IsInSameDocument 使用 方法來檢查指定的 TextPointer 是否位於其他兩個指定的 TextPointer 實例之間,在此情況下,不保證這三個位置都屬於相同的文字容器。

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

備註

大部分涉及多個 TextPointer 實例的作業只有在有問題的實例指出位於相同文字容器範圍中的位置時才有效。 例如, CompareToGetOffsetToPosition 方法不能與 與目前位置相關聯的文字容器外部的位置一起使用 TextPointer 。 使用這個方法,確認指定的 TextPointer 與這類作業的目前位置相容。

適用於