<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <SolidColorBrush x:Key="TreeView_BG_MouseOver" Color="#FFD6DCE5" />
    <SolidColorBrush x:Key="TreeView_BG_Select" Color="#FF47A2E7" />

    <Style x:Key="TreeViewItemFocusVisual" />

    <PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z" />

    <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Width" Value="16" />
        <Setter Property="Height" Value="16" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border
                        Width="16"
                        Height="16"
                        Padding="3,0"
                        Background="#00FFFFFF"
                        Cursor="Hand">
                        <Grid>
                            <Grid
                                Margin="-5"
                                Background="Black"
                                Opacity="0" />
                            <Path
                                x:Name="ExpandPath"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                Data="{StaticResource TreeArrow}"
                                Fill="Gray">
                                <Path.RenderTransform>
                                    <RotateTransform Angle="135" CenterX="3" CenterY="3" />
                                </Path.RenderTransform>
                            </Path>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ExpandPath" Property="Fill" Value="#FFFFBB00" />
                        </Trigger>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="ExpandPath" Property="RenderTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="180" CenterX="3" CenterY="3" />
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="ExpandPath" Property="Fill" Value="Black" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="ExpandPath" Property="Fill" Value="#FF9A9A9A" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}">
        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
        <Setter Property="Padding" Value="1,0,0,0" />
        <Setter Property="FontFamily" Value="Arial" />
        <Setter Property="Background" Value="{DynamicResource TreeView_BG_MouseOver}" />
        <Setter Property="Foreground" Value="{DynamicResource FG_Black}" />
        <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}" />
        <Setter Property="FontSize" Value="16" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" MinWidth="16" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" MinHeight="24" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Border
                            x:Name="Text_BG"
                            Grid.ColumnSpan="3"
                            Margin="-2,2,1,1"
                            Background="{TemplateBinding Background}"
                            Opacity="0" />
                        <ToggleButton
                            x:Name="Expander"
                            ClickMode="Press"
                            IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                            Style="{StaticResource ExpandCollapseToggleStyle}" />
                        <Grid
                            x:Name="TreeViewHeader"
                            Grid.Column="1"
                            HorizontalAlignment="Left"
                            Cursor="Hand">
                            <ContentPresenter
                                x:Name="PART_Header"
                                Margin="2,0,5,0"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="Center"
                                ContentSource="Header"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Grid>
                        <ItemsPresenter
                            x:Name="ItemsHost"
                            Grid.Row="1"
                            Grid.RowSpan="1"
                            Grid.Column="1"
                            Grid.ColumnSpan="2" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="TreeViewHeader" Property="IsMouseOver" Value="True">
                            <Setter TargetName="Text_BG" Property="Opacity" Value="1" />
                            <Setter Property="Foreground" Value="{DynamicResource FG_Blue}" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="Text_BG" Property="BorderThickness" Value="0" />
                            <Setter TargetName="Text_BG" Property="Opacity" Value="1" />
                            <Setter Property="Foreground" Value="{DynamicResource FG_White}" />
                            <Setter TargetName="Text_BG" Property="Background" Value="{DynamicResource TreeView_BG_Select}" />
                        </Trigger>
                        <Trigger Property="IsExpanded" Value="false">
                            <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="HasItems" Value="false">
                            <Setter TargetName="Expander" Property="Visibility" Value="Hidden" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="#FF9A9A9A" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style
        x:Key="TreeView-SecondFloor"
        BasedOn="{StaticResource {x:Type TreeViewItem}}"
        TargetType="{x:Type TreeViewItem}">
        <Setter Property="FontSize" Value="14" />
    </Style>

    <Style x:Key="{x:Type TreeView}" TargetType="{x:Type TreeView}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeView}">
                    <Border
                        x:Name="Border"
                        BorderThickness="1"
                        CornerRadius="1">
                        <ScrollViewer
                            Padding="4"
                            CanContentScroll="False"
                            Focusable="False">
                            <ItemsPresenter />
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="TreeViewItemExtend" TargetType="{x:Type TreeViewItem}">
        <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
        <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
        <Setter Property="Padding" Value="1,0,0,0" />
        <Setter Property="FontFamily" Value="Arial" />
        <Setter Property="Background" Value="{DynamicResource TreeView_BG_MouseOver}" />
        <Setter Property="Foreground" Value="{DynamicResource FG_Black}" />
        <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}" />
        <Setter Property="FontSize" Value="16" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" MinWidth="16" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" MinHeight="24" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Border
                            x:Name="Text_BG"
                            Grid.Column="1"
                            Margin="-2,2,1,1"
                            Background="{TemplateBinding Background}"
                            Opacity="0" />
                        <ToggleButton
                            x:Name="Expander"
                            ClickMode="Press"
                            IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                            Style="{StaticResource ExpandCollapseToggleStyle}" />
                        <Grid
                            x:Name="TreeViewHeader"
                            Grid.Column="1"
                            HorizontalAlignment="Left"
                            Cursor="Hand">
                            <ContentPresenter
                                x:Name="PART_Header"
                                Margin="2,0,5,0"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="Center"
                                ContentSource="Header"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Grid>
                        <ItemsPresenter
                            x:Name="ItemsHost"
                            Grid.Row="1"
                            Grid.RowSpan="1"
                            Grid.Column="1"
                            Grid.ColumnSpan="2" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="TreeViewHeader" Property="IsMouseOver" Value="True">
                            <Setter TargetName="Text_BG" Property="Opacity" Value="1" />
                            <Setter Property="Foreground" Value="{DynamicResource FG_Blue}" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                            <Setter TargetName="Text_BG" Property="BorderThickness" Value="0" />
                            <Setter TargetName="Text_BG" Property="Opacity" Value="1" />
                            <Setter TargetName="Text_BG" Property="Background" Value="{DynamicResource TreeView_BG_Select}" />
                        </Trigger>
                        <Trigger Property="IsExpanded" Value="false">
                            <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="HasItems" Value="false">
                            <Setter TargetName="Expander" Property="Visibility" Value="Hidden" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="#FF9A9A9A" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>


</ResourceDictionary>