■ object 객체에서 XAML을 구하는 방법을 보여준다.
▶ object 객체에서 XAML 구하기 예제 (C#)
1 2 3 4 5 6 7 8 9 |
using System.Windows.Controls; TextBox textBox = new TextBox(); textBox.Name = "textBox"; string xaml = GetXAML(textBox); |
▶ object 객체에서 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 |
using System.Text; using System.Windows.Markup; using System.Xml; #region XAML 구하기 - GetXAML(source) /// <summary> /// XAML 구하기 /// </summary> /// <param name="source">소스 객체</param> /// <returns>XAML</returns> public string GetXAML(object source) { XmlWriterSettings setting = new XmlWriterSettings(); setting.Indent = true; setting.IndentChars = new string(' ', 4); setting.NewLineOnAttributes = true; setting.OmitXmlDeclaration = true; StringBuilder stringBuilder = new StringBuilder(); XmlWriter writer = XmlWriter.Create(stringBuilder, setting); XamlWriter.Save(source, writer); return stringBuilder.ToString(); } #endregion |