[C#/WPF] ListBox 엘리먼트 : AlternationIndex 첨부 속성을 사용해 리스트 박스 항목 배경색/전경색 설정하기
C#/WPF 2020. 9. 10. 01:15728x90
반응형
728x170
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Window 엘리먼트 : 테두리 없는 윈도우 그림자 효과 사용하기 (0) | 2020.09.11 |
---|---|
[C#/WPF] DrawingGroup 엘리먼트 : Transform 속성 사용하기 (0) | 2020.09.11 |
[C#/WPF] DrawingImage 엘리먼트 : DrawingGroup 객체를 사용해 이미지 만들기 (0) | 2020.09.10 |
[C#/WPF] ListBox 엘리먼트 : AlternationConverter 객체를 사용해 그룹 항목 배경색/전경색 설정하기 (0) | 2020.09.10 |
[C#/WPF] ListBox 엘리먼트 : AlternationConverter 객체를 사용해 리스트 박스 항목 배경색/전경색 설정하기 (0) | 2020.09.10 |
[C#/WPF] Button 엘리먼트 : ClickMode 속성 사용하기 (0) | 2020.09.10 |
[C#/WPF] AnimationClock 클래스 : 클럭 컨트롤러 사용하기 (0) | 2020.09.09 |
[C#/WPF] DiscreteDoubleKeyFrame 엘리먼트 : 초침을 끊어서 움직이기 (0) | 2020.09.09 |
[C#/WPF] LinearPointKeyFrame 엘리먼트 : KeyTime 속성에서 Paced 값 사용하기 (0) | 2020.09.09 |
[C#/WPF] PointAnimationUsingKeyFrames 엘리먼트 : 공 순간 움직이기 (0) | 2020.09.09 |
댓글을 달아 주세요