[C#/WPF] XAML 구하기

C#/WPF 2015.04.10 22:03

■ XAML 구하기

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

using System;

using System.Text;

using System.Windows;

using System.Windows.Markup;

using System.Xml;

 

#region XAML 구하기 - GetXAML(frameworkTemplate)

 

/// <summary>

/// XAML 구하기

/// </summary>

/// <param name="frameworkTemplate">프레임워크 템플리트</param>

/// <returns>XAML</returns>

public string GetXAML(FrameworkTemplate frameworkTemplate)

{

    if(frameworkTemplate == null)

    {

        throw new ArgumentNullException("frameworkTemplate");

    }

 

    XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

 

    xmlWriterSettings.Indent              = true;

    xmlWriterSettings.IndentChars         = new string(' ', 4);

    xmlWriterSettings.NewLineOnAttributes = true;

 

    StringBuilder stringBuilder = new StringBuilder();

 

    XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, xmlWriterSettings);

 

    try

    {

        XamlWriter.Save(frameworkTemplate, xmlWriter);

    }

    catch(Exception)

    {

        return string.Empty;

    }

 

    return stringBuilder.ToString();

}

 

#endregion

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

Posted by 사용자 icodebroker
TAG