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

728x90
반응형
728x170

TestProject.zip
다운로드

▶ 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
반응형
그리드형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요