[C#/WPF] TreeView 엘리먼트 : AlternationConverter 객체를 사용해 트리 뷰 항목 배경색/폰트 스타일 설정하기
C#/WPF 2020. 9. 11. 21:57728x90
반응형
728x170
■ TreeView 엘리먼트에서 AlternationConverter 객체를 사용해 트리 뷰 항목의 배경색/폰트 스타일을 설정하는 방법을 보여준다.
▶ 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="TreeView 엘리먼트 : AlternationConverter 객체를 사용해 트리 뷰 항목 배경색/폰트 스타일 설정하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Window.Resources>
<local:LeagueList x:Key="LeagueListKey" />
<AlternationConverter x:Key="TeamBackgroundAlternationConverterKey">
<SolidColorBrush>LimeGreen</SolidColorBrush>
<SolidColorBrush>SpringGreen</SolidColorBrush>
<SolidColorBrush>Chartreuse</SolidColorBrush>
</AlternationConverter>
<AlternationConverter x:Key="DivisionFontStyleAlternationConverterKey">
<FontStyle >Italic</FontStyle>
<FontStyle >Normal</FontStyle>
</AlternationConverter>
<DataTemplate x:Key="TeamDataTemplateKey">
<TextBlock
Text="{Binding Path=Name}"
Background="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}},
Path=(ItemsControl.AlternationIndex),
Converter={StaticResource TeamBackgroundAlternationConverterKey}}" />
</DataTemplate>
<HierarchicalDataTemplate x:Key="DivisionHierarchicalDataTemplateKey"
ItemTemplate="{StaticResource TeamDataTemplateKey}"
ItemsSource="{Binding Path=TeamList}"
AlternationCount="3">
<TextBlock
Text="{Binding Path=Name}"
FontStyle="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeViewItem}},
Path=(ItemsControl.AlternationIndex),
Converter={StaticResource DivisionFontStyleAlternationConverterKey}}" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="LeagueHierarchicalDataTemplateKey"
ItemTemplate="{StaticResource DivisionHierarchicalDataTemplateKey}"
ItemsSource="{Binding Path=DivisionList}">
<TextBlock
FontWeight="Bold"
Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
<Style TargetType="TreeViewItem">
<Setter Property="Padding" Value="1" />
<Setter Property="IsExpanded" Value="True" />
</Style>
</Window.Resources>
<Grid Margin="10">
<TreeView
ItemTemplate="{StaticResource LeagueHierarchicalDataTemplateKey}"
ItemsSource="{Binding Source={StaticResource LeagueListKey}}" />
</Grid>
</Window>
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Material 메뉴 사용하기 (0) | 2020.09.13 |
---|---|
[C#/WPF] Animatable 클래스 : BeginAnimation 메소드를 사용해 공 움직이기 (0) | 2020.09.11 |
[C#/WPF] UIElement 클래스 : BeginAnimation 메소드를 사용해 애니메이션 시작하기 (0) | 2020.09.11 |
[C#/WPF] DoubleAnimation 클래스 : 사각형 높이 변경하기 (0) | 2020.09.11 |
[C#/WPF] Storyboard 클래스 : Begin/Pause/Resume/SkipToFill/SetSpeedRatio/Stop 메소드 사용하기 (0) | 2020.09.11 |
[C#/WPF] VisualBrush 엘리먼트 : 엘리먼트 반사 그림자 이미지 만들기 (0) | 2020.09.11 |
[C#/WPF] DrawingBrush 엘리먼트 : Drawing 속성을 사용해 물고기 브러시 만들기 (0) | 2020.09.11 |
[C#/WPF] DrawingContext 클래스 : DrawDrawing 메소드를 사용해 드로잉 그리기 (0) | 2020.09.11 |
[C#/WPF] DrawingContext 클래스 : DrawImage 메소드를 사용해 이미지 그리기 (0) | 2020.09.11 |
[C#/WPF] DrawingContext 클래스 : DrawGeometry 메소드를 사용해 지오메트리 그리기 (0) | 2020.09.11 |
댓글을 달아 주세요