TextPointer.GetNextContextPosition(LogicalDirection) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정한 논리 방향으로 다음 기호에 대한 포인터를 반환합니다.
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 요청된 방향의 다음 기호에 대한 A이거나 null 현재 TextPointer 가 콘텐츠의 시작 또는 끝에 테두리를 두는 경우입니다.
예제
다음 예제에서는이 메서드에 대 한 사용을 보여 줍니다. 이 예제에서는 메서드와 함께 메서드를 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 요소에 대한 여는 태그 또는 닫는 태그입니다.
UIElement 또는 InlineUIContainer에 BlockUIContainer 포함된 요소입니다. 이러한 UIElement 항상 정확히 하나의 기호로 계산됩니다. UIElement 포함된 추가 콘텐츠 또는 요소는 기호로 계산되지 않습니다.
텍스트 Run 요소 내의 16비트 유니코드 문자입니다.
다음 기호가 로 EmbeddedElementElementStart분류되거나 ElementEnd 메서드에서 식별되는 GetPointerContextTextPointer 경우 이 메서드에서 반환된 기호는 현재 위치에서 정확히 하나의 기호로 진행됩니다.
다음 기호가 분류된 TextTextPointer 경우 이 메서드에서 반환된 텍스트가 텍스트가 아닌 다음 기호(즉, 다음 위치가 아닌 TextPointerContext위치Text)로 이동합니다. 교차된 정확한 기호 수는 메서드를 호출 GetTextRunLength 하여 미리 계산할 수 있습니다.