첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ 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
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요