TextPointerContext Énumération
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Détermine la catégorie de contenu adjacent à un TextPointer dans une LogicalDirection spécifiée.
public enum class TextPointerContext
public enum TextPointerContext
type TextPointerContext =
Public Enum TextPointerContext
- Héritage
Champs
ElementEnd | 4 | TextPointer est adjacent à la balise de fermeture d'un élément TextElement. |
ElementStart | 3 | TextPointer est adjacent à la balise d'ouverture d'un élément TextElement. |
EmbeddedElement | 2 | TextPointer est adjacent à un élément UIElement ou ContentElement incorporé. |
None | 0 | TextPointer est adjacent au début ou à la fin du contenu. |
Text | 1 | TextPointer est adjacent au texte. |
Exemples
// 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.