첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

■ FlowDocument 클래스 : XAML 구하기

------------------------------------------------------------------------------------------------------------------------

using System.Text;

using System.Windows.Documents;

 

#region XAML 구하기 - GetXAML(flowDocument)

 

/// <summary>

/// XAML 구하기

/// </summary>

/// <param name="flowDocument">플로우 문서</param>

/// <returns>XAML</returns>

public string GetXAML(FlowDocument flowDocument)

{

    StringBuilder stringBuilder = new StringBuilder();

 

    Block block = flowDocument.Blocks.FirstBlock;

 

    while(block != null)

    {

        stringBuilder.AppendLine(GetXAML(block));

 

        block = block.NextBlock;

    }

 

    return stringBuilder.ToString();

}

 

#endregion

#region XAML 구하기 - GetXAML(textElement)

 

/// <summary>

/// XAML 구하기

/// </summary>

/// <param name="textElement">텍스트 엘리먼트</param>

/// <returns>XAML</returns>

private string GetXAML(TextElement textElement)

{

    StringBuilder stringBuilder = new StringBuilder();

         

    TextPointer textPointer = textElement.ElementStart;

 

    while(textPointer.CompareTo(textElement.ElementEnd) < 0)

    {

        switch(textPointer.GetPointerContext(LogicalDirection.Forward))

        {

            case TextPointerContext.ElementStart :

 

                stringBuilder.AppendFormat

                (

                    "<{0}>",

                    textPointer.GetAdjacentElement(LogicalDirection.Forward).GetType().Name

                );

 

                break;

 

            case TextPointerContext.ElementEnd :

 

                stringBuilder.AppendFormat

                (

                    "</{0}>",

                    textPointer.GetAdjacentElement(LogicalDirection.Forward).GetType().Name

                );

 

                break;

 

            case TextPointerContext.EmbeddedElement :

 

                stringBuilder.AppendFormat

                (

                    "<{0}/>",

                    textPointer.GetAdjacentElement(LogicalDirection.Forward).GetType().Name

                );

 

                break;

 

            case TextPointerContext.Text :

 

                stringBuilder.Append(textPointer.GetTextInRun(LogicalDirection.Forward));

 

                break;

        }

         

        textPointer = textPointer.GetNextContextPosition(LogicalDirection.Forward);

    }

 

    return stringBuilder.ToString();

}

 

#endregion

------------------------------------------------------------------------------------------------------------------------

728x90
반응형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요