TextPointer.GetNextContextPosition(LogicalDirection) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Belirtilen mantıksal yönde bir sonraki simgeye bir işaretçi döndürür.
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
Parametreler
- direction
- LogicalDirection
Sonraki simgenin LogicalDirection arandığı mantıksal yönü belirten değerlerden biri.
Döndürülenler
TextPointer İstenen yönde bir sonraki simgeye veya null
geçerli TextPointer simge içeriğin başlangıcı veya sonuyla sınırlanırsa.
Örnekler
Aşağıdaki örnekte bu yöntem için bir kullanım gösterilmektedir. Örnek, belirtilen TextElementbir içindeki sembolleri çapraz geçiş yapmak ve ayıklamak için yöntemiyle GetPointerContext birlikte yöntemini kullanırGetNextContextPosition.
Örnek, belirli TextElementbir öğesinin içeriği için bir XAML yapısını ayıklamak için kullanılabilir, ancak yalnızca açıklayıcı amaçlara yöneliktir ve üretim kodunda kullanılmamalıdır. System.Xml XML ile çalışmak ve xml işlemek için tasarlanmış zengin bir tür kümesi için ad alanına bakın.
// 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.
Açıklamalar
Aşağıdakilerden herhangi biri simge olarak kabul edilir:
Bir öğe için TextElement açma veya kapatma etiketi.
UIElement veya BlockUIContaineriçinde bulunan bir InlineUIContainer öğe. Bu tür bir UIElement her zaman tam olarak bir simge olarak sayılır; tarafından UIElement kapsanan ek içerik veya öğeler simge olarak sayılmaz.
Bir metin Run öğesinin içinde 16 bit Unicode karakteri.
Sonraki simge , ElementStartveya ElementEnd (yöntemi tarafından GetPointerContext tanımlandığında) olarak EmbeddedElementkategorilere ayrılmışsaTextPointer, bu yöntem tarafından döndürülen simge geçerli konumdan tam olarak bir simgeyle gelişmiştir.
Sonraki simge olarak TextTextPointer kategorilere ayrılmışsa, bu yöntem tarafından döndürülen metin, metin olmayan bir sonraki simgeye (yani öğesinin olmadığı TextPointerContext Textbir sonraki konuma) ileri doğru ilerler. Kesişen tam simge sayısı, yöntemi çağrılarak GetTextRunLength önceden hesaplanabilir.