첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

■ HierarchicalDataTemplate 엘리먼트 : XML 데이터를 사용해 트리 만들기

------------------------------------------------------------------------------------------------------------------------

TestProject.zip


HelpContent.xml

 

 

<HelpContent xmlns="">

    <Topic

        Header="Copyright Information"

        Source="Help/Copyright.xaml" />

    <Topic

        Header="Program Overview"

        Source="Help/Overview.xaml" />

    <Topic

        Header="The Menu">

        <Topic

            Header="The File Menu"

            Source="Help/FileMenu.xaml" />

        <Topic

            Header="The Help Menu"

            Source="Help/HelpMenu.xaml" />

    </Topic>

</HelpContent>

 

 

HelpWindow.xaml

 

 

<Window x:Class="TestProject.HelpWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    WindowStartupLocation="CenterScreen"

    Width="800"

    Height="600"

    Title="도움말"

    FontFamily="나눔고딕코딩"

    FontSize="16"

    ShowInTaskbar="False">

    <Window.Resources>

        <XmlDataProvider x:Key="XMLDataProviderKey"

            Source="Help/HelpContent.xml"

            XPath="HelpContent" />

        <HierarchicalDataTemplate DataType="Topic" ItemsSource="{Binding XPath=Topic}">

            <StackPanel Orientation="Horizontal">

                <Image Name="image"

                    Margin="2"

                    Stretch="None"

                    Source="Help/HelpImageQuestionMark.png" />

                <TextBlock

                    VerticalAlignment="Center"

                    FontSize="12pt"

                    Text="{Binding XPath=@Header}" />

            </StackPanel>

            <HierarchicalDataTemplate.Triggers>

                <DataTrigger

                    Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=HasItems}"

                    Value="True">

                    <Setter TargetName="image" Property="Image.Source" Value="Help/HelpImageClosedBook.png" />

                </DataTrigger>

                <DataTrigger

                    Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsExpanded}"

                    Value="True">

                    <Setter

                        TargetName="image"

                        Property="Image.Source"

                        Value="Help/HelpImageOpenBook.png" />

                </DataTrigger>

            </HierarchicalDataTemplate.Triggers>

        </HierarchicalDataTemplate>

    </Window.Resources>

    <Grid>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="33*" />

            <ColumnDefinition Width="Auto" />

            <ColumnDefinition Width="67*" />

        </Grid.ColumnDefinitions>

        <TreeView Name="treeView" Grid.Column="0"

            ItemsSource="{Binding Source={StaticResource XMLDataProviderKey}, XPath=Topic}"

            SelectedValuePath="@Source"

            SelectedItemChanged="treeView_SelectedItemChanged" />

        <GridSplitter Grid.Column="1"

            HorizontalAlignment="Center"

            VerticalAlignment="Stretch"

            Width="6" />

        <Frame Name="frame" Grid.Column="2"

            Navigated="frame_Navigated" />

    </Grid>

</Window>

 

------------------------------------------------------------------------------------------------------------------------

728x90
반응형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요