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

1. Person.cs

using System.Windows.Media;

/// <summary>
/// 사람
/// </summary>
public class Person
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region Field

    /// <summary>
    /// 명칭
    /// </summary>
    private string name;

    /// <summary>
    /// 선호 색상
    /// </summary>
    private Color favoriteColor;

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Property
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 명칭 - Name

    /// <summary>
    /// 명칭
    /// </summary>
    public string Name
    {
        get
        {
            return this.name;
        }
        set
        {
            this.name = value;
        }
    }

    #endregion

    #region 선호 색상 - FavoriteColor

    /// <summary>
    /// 선호 색상
    /// </summary>
    public Color FavoriteColor
    {
        get
        {
            return this.favoriteColor;
        }
        set
        {
            this.favoriteColor = value;
        }
    }

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 생성자 - Person()

    /// <summary>
    /// 생성자
    /// </summary>
    public Person()
    {
    }

    #endregion

    #region 생성자 - Person(name, favoriteColor)

    /// <summary>
    /// 생성자
    /// </summary>
    /// <param name="name">명칭</param>
    /// <param name="favoriteColor">선호 색상</param>
    public Person(string name, Color favoriteColor)
    {
        this.name          = name;
        this.favoriteColor = favoriteColor;
    }

    #endregion
}

 

728x90

 

2. Application 엘리먼트에서 Person 클래스를 위한 DataTemplate 리소스를 정의한다.

<Application
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DS.Test.WPF"
    StartupUri="StartPage.xaml">
    <Application.Resources>
        <DataTemplate DataType="{x:Type local:Person}">
            <TextBlock>
                <TextBlock FontWeight="Bold">Name :</TextBlock>
                <TextBlock Text="{Binding Path=Name}" />
                <LineBreak />
                <TextBlock FontWeight="Bold">Favorite Color :</TextBlock>
                <TextBlock Text="{Binding Path=FavoriteColor}" />
            </TextBlock>
        </DataTemplate>
    </Application.Resources>
</Application>

 

300x250

 

3. Person 객체를 NavigationService 객체에서 직접 탐색한다.

...

Person person = new Person("Nancy Davolio", Colors.Yellow);

NavigationService.Navigate(person);

...
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요