■ XmlWriter 클래스의 Create/Save 정적 메소드를 사용해 FrameworkTemplate 객체에서 XAML을 구하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
using System; using System.Text; using System.Windows; using System.Windows.Markup; using System.Xml; #region XAML 구하기 - GetXAML(template) /// <summary> /// XAML 구하기 /// </summary> /// <param name="template">프레임워크 템플리트</param> /// <returns>XAML</returns> public string GetXAML(FrameworkTemplate template) { XmlWriterSettings setting = new XmlWriterSettings(); setting.Indent = true; setting.IndentChars = new string(' ', 4); setting.NewLineOnAttributes = true; StringBuilder stringBuilder = new StringBuilder(); XmlWriter writer = XmlWriter.Create(stringBuilder, setting); try { XamlWriter.Save(template, writer); } catch(Exception) { return string.Empty; } return stringBuilder.ToString(); } #endregion |