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

TestProject.zip
다운로드

▶ SampleCollection.cs

using System.Collections.ObjectModel;

namespace TestProject
{
    /// <summary>
    /// 샘플 컬렉션
    /// </summary>
    public class SampleCollection : ObservableCollection<string>
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - SampleCollection()

        /// <summary>
        /// 생성자
        /// </summary>
        public SampleCollection()
        {
            Add("항목 1");
            Add("항목 2");
            Add("항목 3");
            Add("항목 4");
            Add("항목 5");
        }

        #endregion
    }
}

 

728x90

 

▶ 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="ListBox 엘리먼트 : AlternationIndex 첨부 속성을 사용해 리스트 박스 항목 배경색/전경색 설정하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <local:SampleCollection x:Key="SampleCollectionKey" />
        <Style x:Key="ListBoxItemStyleKey" TargetType="{x:Type ListBoxItem}">
            <Setter Property="Padding"    Value="5"     />
            <Setter Property="Background" Value="Blue"  />
            <Setter Property="Foreground" Value="White" />
            <Style.Triggers>
                <Trigger Property="ListBox.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="CornflowerBlue" />
                    <Setter Property="Foreground" Value="Black"          />
                </Trigger>
                <Trigger Property="ListBox.AlternationIndex" Value="2">
                    <Setter Property="Background" Value="LightBlue" />
                    <Setter Property="Foreground" Value="Navy"      />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <ListBox
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Width="200"
            Height="200"
            Padding="5"
            AlternationCount="3"
            ItemContainerStyle="{StaticResource ListBoxItemStyleKey}"
            ItemsSource="{StaticResource SampleCollectionKey}" />
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요