TextPointer.GetInsertionPosition(LogicalDirection) 메서드

정의

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

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

매개 변수

direction
LogicalDirection

LogicalDirection 가장 가까운 삽입 위치를 검색할 논리적 방향을 지정하는 값 중 하나입니다.

반품

TextPointer 지정된 방향에서 가장 가까운 삽입 위치에 대한 A입니다.

예제

이 예제에서는 메서드를 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.

설명

삽입 위치는 연결된 콘텐츠에 대한 의미 체계 규칙을 위반하지 않고 새 콘텐츠를 추가할 수 있는 위치입니다. 실제로 삽입 위치는 콘텐츠의 어느 곳에나 있으며, 여기서는 캐리트가 배치될 수 있습니다. 삽입 위치가 아닌 유효한 TextPointer 위치의 예는 인접한 두 Paragraph 태그(즉, 이전 단락의 닫는 태그와 다음 단락의 여는 태그 사이) 사이의 위치입니다.

TextPointer 이미 유효한 삽입 위치를 가리키지만 비어 있지 않은 서식 시퀀스에 대한 닫는 태그가 지정된 방향으로 TextPointer 해당 위치 바로 뒤에 오는 경우 이 메서드에서 반환된 위치는 서식 시퀀스 닫기 직후에 삽입 위치를 가리키도록 조정됩니다. 예를 들어 태그 시퀀스를 <Bold>a</Bold>b고려합니다. 문자 a 사이에는 두 개의 삽입 위치가 있습니다 b . 하나는 닫는 태그 앞에, 다른 하나는 닫 BoldBold 태그 바로 뒤에 있습니다. 문자 a 바로 뒤와 닫는 태그 바로 앞의 위치에 호출 TextPointer 되는 경우 GetInsertionPosition 반환된 위치는 닫 BoldBold 는 태그 ForwarddirectionTextPointer 바로 앞의 문자 b바로 앞 위치를 가리키도록 조정됩니다. 반대 논리 방향으로 작업할 때 서식 태그를 여는 경우에도 비슷한 조정이 이루어집니다. 이 메서드는 유사한 경우 삽입 위치 간에 명확성을 제공하기 위한 것입니다.

이 메서드는 구조 태그 시퀀스가 관련될 때 삽입 지점에 대해 선택적으로 사용할 수도 있습니다. 예를 들어 단락 태그를 닫는 위치와 여는 단락 태그 사이의 위치에 있는 경우 방향 매개 변수를 사용하여 다음 단락의 시작 부분(지정) LogicalDirection.Forward또는 이전 단락의 끝에서(지정하여 LogicalDirection.Backward) 가장 가까운 삽입 지점을 선택할 수 있습니다.

포인터가 이미 삽입 위치에 있고 지정된 위치에 인접한 서식 태그가 없는 경우 반환 TextPointer 되는 direction위치는 호출TextPointer과 동일한 위치를 가리킵니다.

가 가리키는 위치를 기준으로 유효한 삽입 위치가 없을 수 있습니다 TextPointer. 이 문제는 참조된 콘텐츠가 빈 테이블이나 목록에서처럼 구조적으로 불완전한 경우에 발생할 수 있습니다. 이러한 경우 이 메서드는 단순히 이 메서드가 TextPointer 호출된 위치와 동일한 위치로 TextPointer 반환합니다. 이 메서드는 항상 유효한 TextPointer.

적용 대상

추가 정보