728x90
반응형
728x170
▶ Place.cs
namespace TestProject
{
/// <summary>
/// 장소
/// </summary>
public class Place
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 명칭
/// </summary>
private string name;
/// <summary>
/// 주
/// </summary>
private string state;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 명칭 - Name
/// <summary>
/// 명칭
/// </summary>
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
#endregion
#region 주 - State
/// <summary>
/// 주
/// </summary>
public string State
{
get
{
return this.state;
}
set
{
this.state = value;
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - Place(name, state)
/// <summary>
/// 생성자
/// </summary>
/// <param name="name">명칭</param>
/// <param name="state">주</param>
public Place(string name, string state)
{
this.name = name;
this.state = state;
}
#endregion
}
}
728x90
▶ PlaceCollection.cs
using System.Collections.ObjectModel;
namespace TestProject
{
/// <summary>
/// 장소 컬렉션
/// </summary>
public class PlaceCollection : ObservableCollection<Place>
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - PlaceCollection()
/// <summary>
/// 생성자
/// </summary>
public PlaceCollection()
{
Add(new Place("Bellevue" , "WA"));
Add(new Place("Gold Beach" , "OR"));
Add(new Place("Kirkland" , "WA"));
Add(new Place("Los Angeles" , "CA"));
Add(new Place("Portland" , "ME"));
Add(new Place("Portland" , "OR"));
Add(new Place("Redmond" , "WA"));
Add(new Place("San Diego" , "CA"));
Add(new Place("San Francisco", "CA"));
Add(new Place("San Jose" , "CA"));
Add(new Place("Seattle" , "WA"));
}
#endregion
}
}
300x250
▶ 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="MultiDataTrigger 엘리먼트 사용하기"
Background="Cornsilk"
FontFamily="나눔고딕코딩"
FontSize="16">
<Window.Resources>
<local:PlaceCollection x:Key="PlaceCollectionKey" />
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=State}" Value="WA">
<Setter Property="Foreground" Value="Red" />
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=Name}" Value="Portland" />
<Condition Binding="{Binding Path=State}" Value="OR" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="Cyan" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
<DataTemplate DataType="{x:Type local:Place}">
<StackPanel Orientation="Horizontal"
Width="200"
Height="30">
<TextBlock
VerticalAlignment="Center"
Width="150"
Padding="5"
Text="{Binding Path=Name}" />
<TextBlock
VerticalAlignment="Center"
Width="50"
Padding="5"
Text="{Binding Path=State}" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center">
<ListBox
HorizontalAlignment="Center"
Background="Honeydew"
ItemsSource="{Binding Source={StaticResource PlaceCollectionKey}}" />
</StackPanel>
</Window>
▶ MainWindow.xaml.cs
using System.Windows;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] ListBox 클래스 : DisplayMemberPath/SelectedValuePath/SelectedValue 속성 사용하기 (0) | 2020.08.11 |
---|---|
[C#/WPF] ListBox 클래스 : ScrollIntoView 메소드를 사용해 특정 항목까지 스크롤하기 (0) | 2020.08.11 |
[C#/WPF] 색상 값 사용하기 (0) | 2020.08.11 |
[C#/WPF] IValueConverter 인터페이스 : 바이트↔실수 변환자 사용하기 (0) | 2020.08.11 |
[C#/WPF] IValueConverter 인터페이스 : 실수→문자열 변환자 사용하기 (0) | 2020.08.11 |
[C#/WPF] AxisAngleRotation3D 엘리먼트 : 3D 애니메이션 사용하기 (0) | 2020.08.10 |
[C#/WPF] DoubleAnimation 엘리먼트 : EasingFunction 속성에서 CircleEase 객체 사용하기 (0) | 2020.08.10 |
[C#/WPF] DoubleAnimation 엘리먼트 : EasingFunction 속성에서 BounceEase 객체 사용하기 (0) | 2020.08.09 |
[C#/WPF] ElasticEase 엘리먼트 사용하기 (0) | 2020.08.09 |
[C#/WPF] Slider 엘리먼트 사용하기 (0) | 2020.08.09 |
댓글을 달아 주세요