Share via


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입니다.

반환

Boolean

textPosition이 현재 위치와 동일한 텍스트 컨테이너 내 위치를 나타내면 true이고, 그렇지 않으면 false입니다.

예외

textPosition이(가) null인 경우

예제

다음 예제는이 메서드의 사용 방법을 보여 줍니다. 예제에서는 합니다 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 인스턴스는 해당 인스턴스는 동일한 텍스트 컨테이너 범위에 있는 위치를 나타내는 경우에 유효한만 합니다. 예를 들어 합니다 CompareTo 하 고 GetOffsetToPosition 메서드를 사용 하 여 사용할 수 없습니다는 TextPointer 현재 위치와 연결 된 텍스트 컨테이너의 외부 위치로. 지정 된 확인 하려면이 메서드를 사용 TextPointer 이러한 작업에 대 한 현재 위치와 호환 됩니다.

적용 대상