<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Geometry x:Key="TreeArrow">F1 M 1.52133,16C 0.750666,16 0.270665,15.1667 0.657333,14.5L 4.37067,8.068L 0.657333,1.63067C -6.35783e-007,0.48 1.71867,-0.509333 2.38533,0.630666L 6.38533,7.568C 6.568,7.876 6.568,8.256 6.38533,8.568L 2.38533,15.5C 2.20933,15.808 1.88133,16 1.52133,16 Z</Geometry>

    <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  x:Name="ExpandBorder"
                             Height="16"
                             Padding="2"
                             Width="16"
                             Background="#01010101"
                             RenderTransformOrigin="0.5 0.5">
                        <Viewbox>
                            <Path x:Name="ExpandPath"
                                  Data="{StaticResource TreeArrow}"
                                  Fill="{DynamicResource Color.Menu.Icon}">
                            </Path>
                        </Viewbox>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked"
                                 Value="True">
                            <Setter Property="RenderTransform"
                                    TargetName="ExpandBorder">
                                <Setter.Value>
                                    <RotateTransform Angle="90" />
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Fill"
                                    TargetName="ExpandPath"
                                    Value="{DynamicResource Color.Menu.Icon}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver"
                                 Value="True">
                            <Setter Property="Fill"
                                    TargetName="ExpandPath"
                                    Value="{DynamicResource Color.Menu.Icon.Hover}" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver"
                                           Value="True" />
                                <Condition Property="IsChecked"
                                           Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Fill"
                                    TargetName="ExpandPath"
                                    Value="{DynamicResource Color.Menu.Icon.Hover}" />
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="TreeViewItemFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type TreeViewItem}">
        <Setter Property="Background"
                Value="Transparent" />
        <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="Foreground"
                Value="{DynamicResource FontColor.Menu.Categories}" />
        <Setter Property="FocusVisualStyle"
                Value="{StaticResource TreeViewItemFocusVisual}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="19"
                                              Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <ToggleButton x:Name="Expander"
                                      ClickMode="Press"
                                      IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                      Style="{StaticResource ExpandCollapseToggleStyle}" />
                        <Border x:Name="Bd"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Grid.Column="1"
                                Padding="{TemplateBinding Padding}"
                                SnapsToDevicePixels="true">
                            <ContentPresenter x:Name="PART_Header"
                                              ContentSource="Header"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Border>
                        <ItemsPresenter x:Name="ItemsHost"
                                        Grid.Column="1"
                                        Grid.ColumnSpan="2"
                                        Grid.Row="1" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded"
                                 Value="false">
                            <Setter Property="Visibility"
                                    TargetName="ItemsHost"
                                    Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="HasItems"
                                 Value="false">
                            <Setter Property="Visibility"
                                    TargetName="Expander"
                                    Value="Hidden" />
                        </Trigger>
                        <Trigger Property="IsSelected"
                                 Value="true">
                            <!--<Setter Property="Background"
                                    TargetName="Bd"
                                    Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />-->
                            <Setter Property="Foreground"
                                    Value="{DynamicResource Color.FunctionMarker}" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected"
                                           Value="true" />
                                <Condition Property="IsSelectionActive"
                                           Value="false" />
                            </MultiTrigger.Conditions>
                            <!--<Setter Property="Background"
                                    TargetName="Bd"
                                    Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}" />-->
                            <Setter Property="Foreground"
                                    Value="{DynamicResource Color.FunctionMarker}" />
                        </MultiTrigger>
                        <Trigger Property="IsEnabled"
                                 Value="false">
                            <Setter Property="Foreground"
                                    Value="{DynamicResource Color.SoftContrast}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="VirtualizingPanel.IsVirtualizing"
                     Value="true">
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>