728x90
반응형
▶ 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="MultiBinding 엘리먼트 : StringFormat 속성을 사용해 문자열 포맷 설정하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Window.Resources>
<local:PurchaseCollection x:Key="PurchaseCollectionKey" />
</Window.Resources>
<Grid>
<ListBox
HorizontalAlignment="Center"
VerticalAlignment="Center"
ItemsSource="{StaticResource PurchaseCollectionKey}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} -- Now only {1:C}!">
<Binding Path="Description" />
<Binding Path="Price" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
728x90
반응형
'C# > WPF' 카테고리의 다른 글
[C#/WPF] StreamGeometry 클래스 : 베지어 곡선(Bezier Curve) 그리기 (0) | 2020.09.23 |
---|---|
[C#/WPF] StreamGeometry 클래스 : 호(Arc) 그리기 (0) | 2020.09.23 |
[C#/WPF] DataTemplateSelector 엘리먼트 사용하기 (0) | 2020.09.22 |
[C#/WPF] GroupStyle 엘리먼트 : HeaderStringFormat 속성을 사용해 헤더 문자열 포맷 설정하기 (0) | 2020.09.22 |
[C#/WPF] Binding 태그 확장 : StringFormat 속성을 사용해 문자열 포맷 설정하기 (0) | 2020.09.22 |
[C#/WPF] MultiBinding 엘리먼트 : StringFormat 속성을 사용해 문자열 포맷 설정하기 (0) | 2020.09.22 |
[C#/WPF] ListBox 엘리먼트 : ItemStringFormat 속성을 사용해 항목 문자열 포맷 설정하기 (0) | 2020.09.22 |
[C#/WPF] Label 엘리먼트 : ContentStringFormat 속성을 사용해 컨텐트 포맷 문자열 설정하기 (0) | 2020.09.22 |
[C#/WPF] TabControl 엘리먼트 : ContentStringFormat 속성을 사용해 컨텐트 포맷 문자열 설정하기 (0) | 2020.09.22 |
[C#/WPF] Dispatcher 클래스 : CheckAccess 메소드를 사용해 메인 스레드 여부 구하기 (0) | 2020.09.21 |
[C#/WPF] EasingDoubleKeyFrame 엘리먼트 : EasingFunction 속성에서 CubicEase/BounceEase 객체 사용하기 (0) | 2020.09.20 |
댓글을 달아 주세요