TextPointer.IsInSameDocument(TextPointer) メソッド

定義

指定された位置が現在の位置と同じテキスト コンテナーに含まれているかどうかを示します。Indicates whether the specified position is in the same text container as the current position.

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

現在の位置と比較する位置を指定する TextPointerA TextPointer that specifies a position to compare to the current position.

戻り値

textPosition が示す位置が現在の位置と同じテキスト コンテナー内にある場合は true。それ以外の場合は falsetrue if textPosition indicates a position that is in the same text container as the current position; otherwise, false.

例外

textPositionnull です。textPosition is null.

このメソッドの使用例を次に示します。The following example demonstrates a use for this method. この例ではIsInSameDocument 、メソッドを使用してTextPointer 、3つのすべてのTextPointer位置が同じテキストコンテナーに属しているという保証がない場合に、指定したが他の2つのインスタンス間に配置されているかどうかを確認します。The example uses the IsInSameDocument method to check whether a specified TextPointer is positioned between two other specified TextPointer instances in a situation when there is no guarantee that all three positions belong to the same text container.

// 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のインスタンスに関連するほとんどの操作は、問題のインスタンスが同じテキストコンテナースコープ内の位置を示している場合にのみ有効です。Most operations that involve multiple TextPointer instances are only valid if the instances in question indicate positions that are in the same text container scope. たとえばCompareTo 、メソッドとGetOffsetToPositionメソッドを、 TextPointer現在の位置に関連付けられているテキストコンテナー外の位置に対して使用することはできません。For example the CompareTo and GetOffsetToPosition methods cannot be used with a TextPointer to a position outside of the text container associated with the current position. このメソッドを使用して、指定TextPointerしたが、このような操作の現在位置と互換性があることを確認します。Use this method to verify that a specified TextPointer is compatible with the current position for such operations.

適用対象