TextPointer.GetNextContextPosition(LogicalDirection) 메서드

정의

지정된 논리 방향의 다음 기호에 대한 포인터를 반환합니다.

public:
 System::Windows::Documents::TextPointer ^ GetNextContextPosition(System::Windows::Documents::LogicalDirection direction);
public System.Windows.Documents.TextPointer GetNextContextPosition (System.Windows.Documents.LogicalDirection direction);
member this.GetNextContextPosition : System.Windows.Documents.LogicalDirection -> System.Windows.Documents.TextPointer
Public Function GetNextContextPosition (direction As LogicalDirection) As TextPointer

매개 변수

direction
LogicalDirection

다음 기호를 검색할 논리 방향을 지정하는 LogicalDirection 값 중 하나입니다.

반환

TextPointer

요청한 방향의 다음 기호에 대한 TextPointer입니다. 현재 TextPointer가 콘텐츠 시작 또는 끝 부분에 인접한 경우 null입니다.

예제

다음 예제는이 메서드의 사용 방법을 보여 줍니다. 예제에서는 합니다 GetNextContextPosition 메서드와 함께 합니다 GetPointerContext 메서드를 트래버스하 고 지정 된 기호를 추출할 TextElement합니다.

이 예제는 지정된 TextElement내용에 대한 XAML 구조를 추출하는 데 사용할 수 있지만 설명용으로만 사용되며 프로덕션 코드에서 사용하면 안 됩니다. 참조 된 System.Xml 다양 한 작업 및 XML을 처리 하기 위한 형식에 대 한 네임 스페이스입니다.

// This method will extract and return a string that contains a representation of 
// the XAML structure of content elements in a given TextElement.        
string GetXaml(TextElement element)
{
    StringBuilder buffer = new StringBuilder();
 
    // Position a "navigator" pointer before the opening tag of the element.
    TextPointer navigator = element.ElementStart;

    while (navigator.CompareTo(element.ElementEnd) < 0)
    {
        switch (navigator.GetPointerContext(LogicalDirection.Forward))
        {
            case TextPointerContext.ElementStart : 
                // Output opening tag of a TextElement
                buffer.AppendFormat("<{0}>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name);
                break;
            case TextPointerContext.ElementEnd :
                // Output closing tag of a TextElement
                buffer.AppendFormat("</{0}>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name);
                break;
            case TextPointerContext.EmbeddedElement :
                // Output simple tag for embedded element
                buffer.AppendFormat("<{0}/>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name);
                break;
            case TextPointerContext.Text :
                // Output the text content of this text run
                buffer.Append(navigator.GetTextInRun(LogicalDirection.Forward));
                break;
        }
 
        // Advance the naviagtor to the next context position.
        navigator = navigator.GetNextContextPosition(LogicalDirection.Forward);
    } // End while.

    return buffer.ToString();
} // End GetXaml method.
' This method will extract and return a string that contains a representation of 
' the XAML structure of content elements in a given TextElement.        
Private Function GetXaml_Renamed(ByVal element As TextElement) As String
    Dim buffer As New StringBuilder()

    ' Position a "navigator" pointer before the opening tag of the element.
    Dim navigator As TextPointer = element.ElementStart

    Do While navigator.CompareTo(element.ElementEnd) < 0
        Select Case navigator.GetPointerContext(LogicalDirection.Forward)
            Case TextPointerContext.ElementStart
                ' Output opening tag of a TextElement
                buffer.AppendFormat("<{0}>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name)
            Case TextPointerContext.ElementEnd
                ' Output closing tag of a TextElement
                buffer.AppendFormat("</{0}>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name)
            Case TextPointerContext.EmbeddedElement
                ' Output simple tag for embedded element
                buffer.AppendFormat("<{0}/>", navigator.GetAdjacentElement(LogicalDirection.Forward).GetType().Name)
            Case TextPointerContext.Text
                ' Output the text content of this text run
                buffer.Append(navigator.GetTextInRun(LogicalDirection.Forward))
        End Select

        ' Advance the naviagtor to the next context position.
        navigator = navigator.GetNextContextPosition(LogicalDirection.Forward)

    Loop ' End while.

    Return buffer.ToString()

End Function ' End GetXaml method.

설명

다음 항목은 기호 간주 됩니다.

  • 여는 태그 또는 닫는 태그가 TextElement 요소입니다.

  • A UIElement 에 포함 된 요소를 InlineUIContainer 또는 BlockUIContainer합니다. 즉, 이러한 참고는 UIElement 은 항상 하나만 기호; 모든 추가 콘텐츠 또는 요소에 포함 된 계산는 UIElement 기호로 계산 되지 않습니다.

  • 텍스트 Run 요소 내의 16비트 유니코드 문자입니다.

다음 기호 자모 인지 하는 경우 EmbeddedElement, ElementStart, 또는 ElementEnd (으로 식별 되는 GetPointerContext 메서드), 해당 TextPointer 이 반환한 메서드는 현재 위치에서 정확히 하나의 기호로 고급입니다.

다음 기호 자모 인지 하는 경우 Text, 해당 TextPointer 이 반환한 메서드에서 텍스트 지난 다음 텍스트가 아닌 기호 (즉, 다음 위치를 TextPointerContext 아닙니다 Text). 호출 하 여 교차 정확한 기호 수를 미리 계산 된 GetTextRunLength 메서드.

적용 대상