첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ XAML 문자열에서 객체를 생성하는 방법을 보여준다.

 

▶ XAML 문자열에서 객체 생성하기 예제 (C#)

using System.Windows.Controls;

string xaml = @"
<Button xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    Foreground=""LightSeaGreen"" FontSize=""24pt"">
    Click me!
</Button>
";

Button button = CreateObject(xaml) as Button;

 

▶ XAML 문자열에서 객체 생성하기 (C#)

using System.IO;
using System.Windows.Markup;

#region 객체 생성하기 - CreateObject(xaml)

/// <summary>
/// 객체 생성하기
/// </summary>
/// <param name="xaml">XAML</param>
/// <returns>생성 객체</returns>
public object CreateObject(string xaml)
{
    MemoryStream memory = new MemoryStream(xaml.Length);

    StreamWriter writer = new StreamWriter(memory);

    writer.Write(xaml);

    writer.Flush();

    memory.Seek(0, SeekOrigin.Begin);

    return XamlReader.Load(memory);
}

#endregion
728x90
그리드형(광고전용)
Posted by icodebroker
,