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

返品

true textPositionが現在の位置と同じテキスト コンテナー内にある位置を示す場合は 2a0/>。それ以外の場合はfalse

例外

textPositionnullです。

次の例では、このメソッドの使用方法を示します。 この例では、 IsInSameDocument メソッドを使用して、3 つの位置がすべて同じテキスト コンテナーに属している保証がない場合に、指定した TextPointer が他の 2 つの指定された 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 インスタンスを含むほとんどの操作は、問題のインスタンスが同じテキスト コンテナー スコープ内の位置を示している場合にのみ有効です。 たとえば、 CompareTo メソッドと GetOffsetToPosition メソッドは、現在の位置に関連付けられているテキスト コンテナーの外側の位置に対する TextPointer では使用できません。 このメソッドを使用して、指定した TextPointer がそのような操作の現在位置と互換性があることを確認します。

適用対象