<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:converters="clr-namespace:Filtration.Converters">
    <converters:TreeViewMarginConverter Length="12" x:Key="TreeViewMarginConverter" />
    <Style x:Key="TreeViewItemFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Border>
                        <Rectangle Margin="0,0,0,0"
                                   StrokeThickness="5"
                                   Stroke="Black"
                                   StrokeDashArray="1 2"
                                   Opacity="0" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <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}">
                    <Grid Background="Transparent"
                              Height="16"
                              Width="16">
                        <Path x:Name="ExpandPath" 
                                  HorizontalAlignment="Center"
                                  VerticalAlignment="Center"
                                  Data="{StaticResource TreeArrow}"
                                  Fill="Transparent"
                                  Stroke="{StaticResource BlackBrush}">
                            <Path.RenderTransform>
                                <RotateTransform Angle="135" CenterY="3" CenterX="3" />
                            </Path.RenderTransform>
                        </Path>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="RenderTransform" TargetName="ExpandPath">
                                <Setter.Value>
                                    <RotateTransform Angle="180" CenterY="3" CenterX="3" />
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource GrayBrush1}" />
                            <Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource BlackBrush}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource GrayBrush5}" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsEnabled" Value="False" />
                                <Condition Property="IsChecked" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource GrayBrush5}" />
                            <Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource GrayBrush5}" />
                        </MultiTrigger>
                        <Trigger Property="IsMouseOver"
                                 Value="True">
                            <Setter Property="Stroke" TargetName="ExpandPath" Value="{StaticResource GrayBrush3}" />
                            <Setter Property="Fill" TargetName="ExpandPath" Value="{StaticResource GrayBrush6}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type TreeViewItem}">
        <Setter Property="MinHeight" Value="25" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="Background" Value="White" />
        <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <StackPanel>
                        <Border x:Name="TreeViewItemBorder"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}"
                                    MinHeight="{TemplateBinding MinHeight}"
                                    UseLayoutRounding="True"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <Grid Margin="{Binding Converter={StaticResource TreeViewMarginConverter}, RelativeSource={x:Static RelativeSource.TemplatedParent}}" Background="Transparent" VerticalAlignment="Stretch">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition MinWidth="19" Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <ToggleButton x:Name="Expander"
                                                  Style="{StaticResource ExpandCollapseToggleStyle}"
                                                  IsChecked="{Binding Path=IsExpanded, RelativeSource={x:Static RelativeSource.TemplatedParent}, Mode=TwoWay}"
                                                  ClickMode="Press" />
                                <ContentPresenter x:Name="PART_Header"
                                                      Grid.Column="1"
                                                      ContentSource="Header"
                                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                            </Grid>
                        </Border>
                        <ItemsPresenter x:Name="ItemsHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <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 SourceName="TreeViewItemBorder" Property="IsMouseOver" Value="True">
                            <Setter TargetName="TreeViewItemBorder" Property="Background" Value="{StaticResource GrayBrush6}" />
                            <Setter Property="Foreground" Value="Black" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="TreeViewItemBorder" Property="Background" Value="{StaticResource GrayBrush5}" />
                            <Setter Property="Foreground" Value="Red" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{StaticResource GrayBrush7}" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsEnabled" Value="False" />
                                <Condition Property="IsSelected" Value="True" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="TreeViewItemBorder" Property="Background" Value="{StaticResource GrayBrush7}" />
                                <Setter Property="Foreground" Value="{StaticResource GrayBrush6}" />
                            </MultiTrigger.Setters>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="True" />
                                <Condition Property="Selector.IsSelectionActive" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="TreeViewItemBorder" Property="Background" Value="{StaticResource GrayBrush5}" />
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>