Export (0) Print
Expand All
Expand Minimize

TextPointerContext Enumeration

Determines the category of content that is adjacent to a TextPointer in a specified LogicalDirection.

Namespace:  System.Windows.Documents
Assembly:  PresentationFramework (in PresentationFramework.dll)

public enum TextPointerContext
<object property="enumerationMemberName" .../>

Member nameDescription
ElementEndThe TextPointer is adjacent to the closing tag of a TextElement.
ElementStartThe TextPointer is adjacent to the opening tag of a TextElement.
EmbeddedElementThe TextPointer is adjacent to an embedded UIElement or ContentElement.
NoneThe TextPointer is adjacent to the beginning or end of content.
TextThe TextPointer is adjacent to text.

// 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.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft