TextPointer 클래스

정의

FlowDocument 또는 TextBlock 내의 위치를 나타냅니다.

public ref class TextPointer : System::Windows::Documents::ContentPosition
public class TextPointer : System.Windows.Documents.ContentPosition
type TextPointer = class
    inherit ContentPosition
Public Class TextPointer
Inherits ContentPosition
상속
TextPointer

예제

다음 예제에 사용 하는 방법을 보여 줍니다.는 TextPointer 첫 번째 내부 위치를 찾으려면 Run 된 지정 된 텍스트 컨테이너의에서 요소입니다.

// This method returns the position just inside of the first text Run (if any) in a 
// specified text container.
TextPointer FindFirstRunInTextContainer(DependencyObject container)
{
    TextPointer position = null;

    if (container != null){
        if (container is FlowDocument)
            position = ((FlowDocument)container).ContentStart;
        else if (container is TextBlock)
            position = ((TextBlock)container).ContentStart;
        else
            return position;
    }
    // Traverse content in forward direction until the position is immediately after the opening 
    // tag of a Run element, or the end of content is encountered.
    while (position != null)
    {
        // Is the current position just after an opening element tag?
        if (position.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart)
        {
            // If so, is the tag a Run?
            if (position.Parent is Run)
                break;
        }

        // Not what we're looking for; on to the next position.
        position = position.GetNextContextPosition(LogicalDirection.Forward);
    }
        
    // This will be either null if no Run is found, or a position just inside of the first Run element in the
    // specifed text container.  Because position is formed from ContentStart, it will have a logical direction
    // of Backward.
    return position;
}
' This method returns the position just inside of the first text Run (if any) in a 
' specified text container.
Private Function FindFirstRunInTextContainer(ByVal container As DependencyObject) As TextPointer
    Dim position As TextPointer = Nothing

    If container IsNot Nothing Then
        If TypeOf container Is FlowDocument Then
            position = (CType(container, FlowDocument)).ContentStart
        ElseIf TypeOf container Is TextBlock Then
            position = (CType(container, TextBlock)).ContentStart
        Else
            Return position
        End If
    End If
    ' Traverse content in forward direction until the position is immediately after the opening 
    ' tag of a Run element, or the end of content is encountered.
    Do While position IsNot Nothing
        ' Is the current position just after an opening element tag?
        If position.GetPointerContext(LogicalDirection.Backward) = TextPointerContext.ElementStart Then
            ' If so, is the tag a Run?
            If TypeOf position.Parent Is Run Then
                Exit Do
            End If
        End If

        ' Not what we're looking for on to the next position.
        position = position.GetNextContextPosition(LogicalDirection.Forward)
    Loop

    ' This will be either null if no Run is found, or a position just inside of the first Run element in the
    ' specifed text container.  Because position is formed from ContentStart, it will have a logical direction
    ' of Backward.
    Return position
End Function

다음 예제에서는 사용 하 여 간단한 찾기 알고리즘 구현 TextPointer 기능입니다.

// This method will search for a specified word (string) starting at a specified position.
TextPointer FindWordFromPosition(TextPointer position, string word)
{
    while (position != null)
    {
         if (position.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
         {
             string textRun = position.GetTextInRun(LogicalDirection.Forward);

             // Find the starting index of any substring that matches "word".
             int indexInRun = textRun.IndexOf(word);
             if (indexInRun >= 0)
             {
                 position = position.GetPositionAtOffset(indexInRun);
                 break;
             }
         }
         else
        {
            position = position.GetNextContextPosition(LogicalDirection.Forward);
        }
    }

     // position will be null if "word" is not found.
     return position; 
}
' This method will search for a specified word (string) starting at a specified position.
Private Function FindWordFromPosition(ByVal position As TextPointer, ByVal word As String) As TextPointer
    Do While position IsNot Nothing
        If position.GetPointerContext(LogicalDirection.Forward) = TextPointerContext.Text Then
            Dim textRun As String = position.GetTextInRun(LogicalDirection.Forward)

            ' Find the starting index of any substring that matches "word".
            Dim indexInRun As Integer = textRun.IndexOf(word)
            If indexInRun >= 0 Then
                position = position.GetPositionAtOffset(indexInRun)
                Exit Do
            End If
        Else
            position = position.GetNextContextPosition(LogicalDirection.Forward)
        End If
    Loop

    ' position will be null if "word" is not found.
    Return position
End Function

설명

TextPointer 클래스에서는 다음 용어를 소개 합니다.

  • 위치-기본적으로, 한 TextPointer 항상 가리킵니다를 위치 콘텐츠에서. 이러한 위치 콘텐츠 전체에서 문자 간이나 흐름 콘텐츠 요소는 콘텐츠에 대 한 구조를 정의 합니다.

  • 때문에 현재 위치-는 TextPointer 항상 된 위치를 나타냅니다 이므로 통해 수행할 수 있는 작업의 많은 TextPointer 에서 가리키는 현재 위치를 기준으로는 TextPointer를 지칭 하는 것이 으로 지정 된 위치를 TextPointer 으로 현재 위치 합니다.

  • 삽입 위치-는 삽입 위치 는 관련된 콘텐츠에 대 한 의미 체계 규칙을 위반 하지 않고 새 콘텐츠를 추가할 수 있는 위치입니다. 실제로 삽입 위치는 콘텐츠 내 캐럿을 배치할 수 있습니다. 유효한 예가 TextPointer 삽입 위치 하지 않은 위치는 두 인접 한 위치 Paragraph 태그 (즉, 여는 태그 다음 단락의 이전 단락의 닫는 태그 사이).

  • 기호-의 목적 TextPointer 것으로 간주 됩니다 기호를 포함 하는 작업을 다음 중 하나는 기호:

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

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

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

  • 텍스트 컨테이너-A 원하는 텍스트 컨테이너 최종 테두리 당면한 유동 콘텐츠를 구성 하는 요소 않으면 가리키는 위치를 TextPointer 항상 텍스트 컨테이너 내에 포함 합니다. 현재 텍스트 컨테이너 중 하나 여야 합니다는 FlowDocument 또는 TextBlock합니다. 일반적으로, 간의 작업 TextPointer 인스턴스가 다른 텍스트 컨테이너에서 지원 되지 않습니다.

  • 문서의 현재 항목-텍스트 컨테이너의 콘텐츠 라고는 문서 에서 같이 합니다 IsInSameDocument 메서드 및 DocumentStartDocumentEnd 속성입니다.

클래스는 TextPointer WPF(Windows Presentation Foundation) 흐름 콘텐츠 요소로 표현되는 콘텐츠의 통과 및 조작을 용이하게 하기 위한 것입니다. 일반적으로 이러한 요소는 파생TextElement됩니다. 작업 중 일부는 TextPointer 용이 하 게 다음과 같습니다.

위치 및 LogicalDirection 나타난를 TextPointer 개체는 변경할 수 없습니다. 콘텐츠 되었거나 편집 수정 하 여 표시 되는 위치를 TextPointer 주변 된 텍스트를 기준으로 바뀌지 대신 콘텐츠의 시작 부분에서 해당 위치의 오프셋에서 새 상대 위치를 반영 하도록 알맞게 조정 됩니다 콘텐츠입니다. 예를 들어, 한 TextPointer 나타내는, 콘텐츠를 삽입 하거나 전이나 단락 뒤 삭제 하는 경우에 해당 단락 시작 부분을 가리키도록 지정 단락의 시작 위치를 계속 합니다.

TextPointer 클래스는 공용 생성자를 제공 하지 않습니다. 인스턴스의 TextPointer 속성 또는 다른 개체의 메서드를 사용 하 여 만들어집니다 (기타를 포함 하 여 TextPointer 개체). 다음 목록에서는 몇 가지 예가 만들고 반환 하는 메서드 및 속성을 TextPointer입니다. 이 목록은 전체 목록이 아닙니다.

속성

DocumentEnd

현재 위치와 연결된 텍스트 컨테이너의 콘텐츠 끝 부분에서 TextPointer를 가져옵니다.

DocumentStart

현재 위치와 연결된 텍스트 컨테이너의 콘텐츠 시작 부분에서 TextPointer를 가져옵니다.

HasValidLayout

현재 위치와 연결된 텍스트 컨테이너의 레이아웃이 올바른지(최신인지) 여부를 나타내는 값을 가져옵니다.

IsAtInsertionPosition

현재 위치가 삽입 위치인지 여부를 나타내는 값을 가져옵니다.

IsAtLineStartPosition

현재 위치가 줄의 시작 부분에 있는지 여부를 나타내는 값을 가져옵니다.

LogicalDirection

현재 위치와 연결된 콘텐츠를 구분하는 데 사용되는 현재 위치와 연결된 논리 방향을 가져옵니다.

Paragraph

현재 위치의 범위를 지정하는 단락이 있으면 가져옵니다.

Parent

현재 위치의 범위를 지정하는 논리 부모를 가져옵니다.

메서드

CompareTo(TextPointer)

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

DeleteTextInRun(Int32)

현재 TextPointer로 표시되는 위치에서 지정된 수의 문자를 삭제합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetAdjacentElement(LogicalDirection)

지정된 논리 방향으로 현재 TextPointer에 인접한 요소가 있으면 반환합니다.

GetCharacterRect(LogicalDirection)

지정된 논리 방향으로 현재 Rect에 인접한 콘텐츠의 경계 상자(TextPointer)를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetInsertionPosition(LogicalDirection)

지정된 논리 방향으로 가장 가까운 삽입 위치에 대한 TextPointer를 반환합니다.

GetLineStartPosition(Int32)

현재 TextPointer에 상대적으로 지정된 줄의 시작 부분에 대한 TextPointer를 반환합니다.

GetLineStartPosition(Int32, Int32)

현재 TextPointer에 상대적으로 지정된 줄의 시작 부분에 대한 TextPointer를 반환하고 건너뛴 줄 수를 보고합니다.

GetNextContextPosition(LogicalDirection)

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

GetNextInsertionPosition(LogicalDirection)

지정된 논리 방향의 다음 삽입 위치에 대한 TextPointer를 반환합니다.

GetOffsetToPosition(TextPointer)

현재 TextPointer와 지정된 두 번째 TextPointer 사이의 기호 수를 반환합니다.

GetPointerContext(LogicalDirection)

지정된 논리 방향으로 현재 TextPointer에 인접한 콘텐츠의 범주 표시기를 반환합니다.

GetPositionAtOffset(Int32)

현재 TextPointer 시작 부분에서 지정된 오프셋(기호)으로 표시되는 위치에 대한 TextPointer를 반환합니다.

GetPositionAtOffset(Int32, LogicalDirection)

현재 TextPointer의 시작 부분에서 지정된 방향으로 지정된 오프셋(기호)으로 표시되는 위치에 대한 TextPointer를 반환합니다.

GetTextInRun(LogicalDirection)

지정된 논리 방향으로 현재 TextPointer에 인접한 텍스트를 포함하는 문자열을 반환합니다.

GetTextInRun(LogicalDirection, Char[], Int32, Int32)

지정된 방향으로 인접한 텍스트에서 지정된 최대 수의 문자를 호출자가 제공한 문자 배열에 복사합니다.

GetTextRunLength(LogicalDirection)

지정된 방향으로 현재 TextPointer와 텍스트가 아닌 다음 기호 사이의 유니코드 문자 수를 반환합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
InsertLineBreak()

현재 위치에 줄 바꿈을 삽입합니다.

InsertParagraphBreak()

현재 위치에 단락 나누기를 삽입합니다.

InsertTextInRun(String)

지정된 텍스트를 현재 위치의 Run 텍스트에 삽입합니다.

IsInSameDocument(TextPointer)

지정된 위치가 현재 위치와 동일한 텍스트 컨테이너 내에 있는지 여부를 나타냅니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

이 형식 또는 멤버는 WPF(Windows Presentation Foundation) 인프라를 지원하며 사용자 코드에서 직접 사용할 수 없습니다.

적용 대상

추가 정보