namespace CustomXaml
{
using System;
public class Person
{
public Person()
{
this.Birthday = DateTime.Now;
}
public DateTime Birthday { get; private set; }
}
}
위와 같이 클래스를 선언하여
<p:Person xmlns:p="clr-namespace:CustomXaml;assembly=CustomXaml" />
위와 같이 해당 클래스를 XAML 에 선언한 경우
아래와 같은 형식으로 XAML 을 로드해온다.
namespace CustomXaml
{
using System;
using System.Windows.Markup;
class Program
{
public static void Main(string[] args)
{
// 어셈블리에서 대상인 XAML 의 스트림을 구함
var s = typeof(Program).Assembly.GetManifestResourceStream("CustomXaml.Person.xaml");
// 패스
var p = XamlReader.Load(s) as Person;
// property를 표시함
Console.WriteLine("p.Birthday = {0}", p.Birthday);
}
}
}
'Windows > C#/WPF' 카테고리의 다른 글
| 레이아웃 종류 (0) | 2021.05.01 |
|---|---|
| Object 요소 property (0) | 2021.05.01 |
| WPF XAML 스타일 정의 예제 (0) | 2021.04.29 |
| WPF 의 구성 (0) | 2021.04.28 |
| C# Framework 프로젝트에서 WPF 사용하는 예제 (0) | 2021.04.28 |
댓글