TextPointer.GetNextContextPosition(LogicalDirection) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Restituisce un puntatore al simbolo successivo nella direzione logica specificata.
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
Parametri
- direction
- LogicalDirection
Uno dei LogicalDirection valori che specifica la direzione logica in cui cercare il simbolo successivo.
Valori restituiti
Oggetto TextPointer al simbolo successivo nella direzione richiesta oppure null se l'oggetto corrente TextPointer delimita l'inizio o la fine del contenuto.
Esempio
Nell'esempio seguente viene illustrato un utilizzo per questo metodo. Nell'esempio viene utilizzato il GetNextContextPosition metodo insieme al GetPointerContext metodo per attraversare ed estrarre i simboli in un oggetto specificato TextElement.
Anche se l'esempio può essere usato per estrarre una struttura XAML per il contenuto di un determinato TextElementoggetto , è destinato solo a scopi illustrativi e non deve essere usato nel codice di produzione. Vedere lo spazio dei nomi per un set completo di tipi progettati per l'uso e l'elaborazione 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.
Commenti
Uno dei seguenti è considerato un simbolo:
Tag di apertura o chiusura per un elemento TextElement.
Elemento UIElement contenuto in un InlineUIContainer oggetto o BlockUIContainer. Si noti che tale UIElement viene sempre conteggiato come esattamente un simbolo; qualsiasi contenuto o elemento aggiuntivo contenuto dall'UIElement non viene conteggiato come simboli.
Carattere Unicode a 16 bit all'interno di un elemento di testo Run .
Se il simbolo successivo viene categorizzato come EmbeddedElement, ElementStarto ElementEnd (come identificato dal GetPointerContext metodo ), l'oggetto TextPointer restituito da questo metodo viene avanzato esattamente da un simbolo dalla posizione corrente.
Se il simbolo successivo è categorizzato come Text, l'oggetto TextPointer restituito da questo metodo viene avanzato oltre il testo al simbolo non di testo successivo ( ovvero la posizione successiva in cui TextPointerContext non Textè ). Il conteggio esatto dei simboli incrociati può essere calcolato in anticipo chiamando il GetTextRunLength metodo .