<ui:Page
    x:Class="ModernWpf.SampleApp.ControlPages.TreeViewPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ui="http://schemas.modernwpf.com/2019"
    xmlns:local="clr-namespace:ModernWpf.SampleApp.ControlPages"
    xmlns:sc="clr-namespace:SamplesCommon;assembly=SamplesCommon"
    mc:Ignorable="d">

    <Page.Resources>
        <HierarchicalDataTemplate
            x:Key="FolderTemplate"
            ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal">
                <Image
                    Width="20"
                    Source="/Assets/folder.png" />
                <TextBlock Margin="0,0,10,0" />
                <TextBlock Text="{Binding Name}" />
            </StackPanel>
        </HierarchicalDataTemplate>

        <DataTemplate x:Key="FileTemplate">
            <StackPanel Orientation="Horizontal">
                <Image
                    Width="20"
                    Source="/Assets/file.png" />
                <TextBlock Margin="0,0,10,0" />
                <TextBlock Text="{Binding Name}" />
            </StackPanel>
        </DataTemplate>

        <local:ExplorerItemTemplateSelector
            x:Key="ExplorerItemTemplateSelector"
            FolderTemplate="{StaticResource FolderTemplate}"
            FileTemplate="{StaticResource FileTemplate}" />
    </Page.Resources>

    <ScrollViewer>
        <ui:SimpleStackPanel Style="{StaticResource ControlPageContentPanelStyle}">
            <sc:ControlExample HeaderText="A simple TreeView">
                <Border
                    Height="400"
                    HorizontalAlignment="Left"
                    BorderBrush="{DynamicResource SystemControlForegroundBaseMediumLowBrush}"
                    BorderThickness="1">
                    <TreeView
                        x:Name="sampleTreeView"
                        MinWidth="345"
                        MaxHeight="400"
                        Margin="0,12,0,0"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Top">
                        <TreeViewItem
                            Header="Work Documents"
                            IsExpanded="True">
                            <TreeViewItem Header="XYZ Functional Spec" />
                            <TreeViewItem Header="Feature Schedule" />
                            <TreeViewItem Header="Overall Project Plan" />
                            <TreeViewItem Header="Feature Resources Allocation" />
                        </TreeViewItem>
                        <TreeViewItem
                            Header="Personal Documents"
                            IsExpanded="True">
                            <TreeViewItem
                                Header="Home Remodel"
                                IsExpanded="True">
                                <TreeViewItem Header="Contractor Contact Info" />
                                <TreeViewItem Header="Paint Color Scheme" />
                                <TreeViewItem Header="Flooring woodgrain type" />
                                <TreeViewItem Header="Kitchen cabinet style" />
                            </TreeViewItem>
                        </TreeViewItem>
                    </TreeView>
                </Border>
            </sc:ControlExample>

            <sc:ControlExample HeaderText="A TreeView with DataBinding Using ItemSource">
                <sc:ControlExample.Example>
                    <Border
                        Height="400"
                        BorderBrush="{DynamicResource TextControlBorderBrush}"
                        BorderThickness="1">
                        <TreeView
                            x:Name="TreeView1"
                            MinWidth="345"
                            MaxHeight="400"
                            Margin="0,12,0,0"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Top"
                            ItemsSource="{Binding}">
                            <TreeView.ItemContainerStyle>
                                <Style TargetType="TreeViewItem" BasedOn="{StaticResource DefaultTreeViewItemStyle}">
                                    <Setter Property="IsExpanded" Value="True" />
                                </Style>
                            </TreeView.ItemContainerStyle>
                            <TreeView.ItemTemplate>
                                <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                                    <TextBlock Text="{Binding Name}" />
                                </HierarchicalDataTemplate>
                            </TreeView.ItemTemplate>
                        </TreeView>
                    </Border>
                </sc:ControlExample.Example>
            </sc:ControlExample>

            <sc:ControlExample HeaderText="A TreeView with ItemTemplateSelector">
                <sc:ControlExample.Example>
                    <Border
                        Height="400"
                        BorderBrush="{DynamicResource TextControlBorderBrush}"
                        BorderThickness="1">
                        <TreeView
                            x:Name="FileTree"
                            MinWidth="345"
                            MaxHeight="400"
                            Margin="0,12,0,0"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Top"
                            ItemsSource="{Binding}"
                            ItemTemplateSelector="{StaticResource ExplorerItemTemplateSelector}">
                            <TreeView.ItemContainerStyle>
                                <Style TargetType="TreeViewItem" BasedOn="{StaticResource DefaultTreeViewItemStyle}">
                                    <Setter Property="IsExpanded" Value="True" />
                                </Style>
                            </TreeView.ItemContainerStyle>
                        </TreeView>
                    </Border>
                </sc:ControlExample.Example>
            </sc:ControlExample>
        </ui:SimpleStackPanel>
    </ScrollViewer>
</ui:Page>
