첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

TestProject.zip
다운로드

▶ Purchase.cs

using System;

namespace TestProject
{
    /// <summary>
    /// 구매
    /// </summary>
    public class Purchase 
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 설명 - Description

        /// <summary>
        /// 설명
        /// </summary>
        public string Description { get; set; }

        #endregion
        #region 가격 - Price

        /// <summary>
        /// 가격
        /// </summary>
        public double Price { get; set; }

        #endregion
        #region 제안 만기일 - OfferExpiredDate

        /// <summary>
        /// 제안 만기일
        /// </summary>
        public DateTime OfferExpiredDate { get; set; }

        #endregion

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

        #region 생성자 - Purchase()

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

        #endregion
        #region 생성자 - Purchase(description, price, offerExpiredDate)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="description">설명</param>
        /// <param name="price">가격</param>
        /// <param name="offerExpiredDate">제안 만기일</param>
        public Purchase(string description, double price, DateTime offerExpiredDate)
        {
            Description      = description;
            Price            = price;
            OfferExpiredDate = offerExpiredDate;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 문자열 구하기 - ToString()

        /// <summary>
        /// 문자열 구하기
        /// </summary>
        /// <returns>문자열</returns>
        public override string ToString()
        {
            return String.Format("{0}, {1:c}, {2:D}", Description, Price, OfferExpiredDate);
        }

        #endregion
    }
}

 

▶ PurchaseCollection.cs

using System;
using System.Collections.ObjectModel;

namespace TestProject
{
    /// <summary>
    /// 구매 컬렉션
    /// </summary>
    public class PurchaseCollection : ObservableCollection<Purchase>
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - PurchaseCollection()

        /// <summary>
        /// 생성자
        /// </summary>
        public PurchaseCollection()
        {
            Add((new Purchase("Snowboard and bindings"   , 120   , new DateTime(2009, 1, 1 ))));
            Add((new Purchase("Inside C#, second edition", 10    , new DateTime(2009, 2, 2 ))));
            Add((new Purchase("Laptop - only 1 year old" , 499.99, new DateTime(2009, 2, 28))));
            Add((new Purchase("Set of 6 chairs"          , 120   , new DateTime(2009, 2, 28))));
            Add((new Purchase("My DVD Collection"        , 15    , new DateTime(2009, 1, 1 ))));
            Add((new Purchase("TV Drama Series"          , 39.985, new DateTime(2009, 1, 1 ))));
            Add((new Purchase("Squash racket"            , 60    , new DateTime(2009, 2, 28))));
        }

        #endregion
    }
}

 

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TestProject"
    Width="800"
    Height="600"
    Title="Binding 태그 확장 : StringFormat 속성을 사용해 문자열 포맷 설정하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <local:PurchaseCollection x:Key="PurchaseCollectionKey"  />
    </Window.Resources>
    <Grid>
        <ListView
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            ItemsSource="{StaticResource PurchaseCollectionKey}">
            <ListView.View>
                <GridView>
                    <GridViewColumn
                        Header="Description"
                        DisplayMemberBinding="{Binding Path=Description}" />
                    <GridViewColumn
                        Header="Price"
                        DisplayMemberBinding="{Binding Path=Price, StringFormat=Now {0:c}!}" />
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</Window>
728x90
반응형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요