TextPointer.CompareTo(TextPointer) 메서드

정의

현재 TextPointer와 지정된 두 번째 TextPointer에 지정된 위치 사이에 서수 비교를 수행합니다.

public:
 int CompareTo(System::Windows::Documents::TextPointer ^ position);
public int CompareTo (System.Windows.Documents.TextPointer position);
member this.CompareTo : System.Windows.Documents.TextPointer -> int
Public Function CompareTo (position As TextPointer) As Integer

매개 변수

position
TextPointer

현재 위치와 비교할 위치를 지정하는 TextPointer입니다.

반환

현재 TextPointerposition 앞에 오면 –1이고, 위치가 동일하면 0이고, 현재 TextPointerposition 뒤에 오면 +1입니다.

예외

position이 현재 위치와 연결된 텍스트 컨테이너의 외부 위치를 지정하는 경우

예제

다음 예제는이 메서드의 사용 방법을 보여 줍니다. 예에서를 CompareTo 메서드를 함께에서 사용 합니다 GetInsertionPosition 메서드는 지정 된 테스트를 TextElement 비어.

// Tests to see if the specified TextElement is empty (has no printatble content).
bool IsElementEmpty(TextElement element)
{
    // Find starting and ending insertion positions in the element.
    // Inward-facing directions are used to make sure that insertion position
    // will be found correctly in case when the element may contain inline 
    // formatting elements (such as a Span or Run that contains Bold or Italic elements).
    TextPointer start = element.ContentStart.GetInsertionPosition(LogicalDirection.Forward);
    TextPointer end = element.ContentEnd.GetInsertionPosition(LogicalDirection.Backward);
     
    // The element has no printable content if its first and last insertion positions are equal.
    return start.CompareTo(end) == 0;
} // End IsEmptyElement method.
' Tests to see if the specified TextElement is empty (has no printatble content).
Private Function IsElementEmpty(ByVal element As TextElement) As Boolean
    ' Find starting and ending insertion positions in the element.
    ' Inward-facing directions are used to make sure that insertion position
    ' will be found correctly in case when the element may contain inline 
    ' formatting elements (such as a Span or Run that contains Bold or Italic elements).
    Dim start As TextPointer = element.ContentStart.GetInsertionPosition(LogicalDirection.Forward)
    Dim [end] As TextPointer = element.ContentEnd.GetInsertionPosition(LogicalDirection.Backward)

    ' The element has no printable content if its first and last insertion positions are equal.
    Return start.CompareTo([end]) = 0

End Function ' End IsEmptyElement method.

설명

-1 값은 현재 TextPointer 로 지정된 위치가 로 지정된 position위치 앞에 있음을 나타냅니다. 0 값 표시 되는 위치가 같은지를 나타냅니다. 양의 + 1 값을 현재 지정 된 위치가 TextPointer 으로 지정 된 위치 뒤에 옵니다 position합니다.

적용 대상

추가 정보