<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:dhcc="http://www.dhcc.com.cn"
                    xmlns:local="clr-namespace:Platform.Controls.TableContainer"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic">

    <SolidColorBrush x:Key="GlyphBrush" Color="#444" />

    <local:MenuToIndentConverter x:Key="mtidc" />

    <Style x:Key="TreeViewItemFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Width" Value="15" />
        <Setter Property="Height" Value="15" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border Width="15" Height="13">
                        <Border Width="9"
                                Height="9"
                                Background="Transparent"
                                BorderBrush="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"
                                BorderThickness="0"
                                SnapsToDevicePixels="true">
                            <Path x:Name="ExpandPath"
                                  Width="Auto"
                                  Height="Auto"
                                  Margin="2"
                                  Data="M 0,0 L 4,3.5 L 0,7 Z"
                                  Fill="Gray"
                                  RenderTransformOrigin="0.5,0.5"
                                  Stretch="Fill" />
                        </Border>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="ExpandPath" Property="Data" Value="M 0,0 L 3.5,4 L 7,0 Z" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ImageToggleStyle" TargetType="ToggleButton">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleButton">
                    <Grid Width="{TemplateBinding Width}"
                          Height="{TemplateBinding Height}"
                          Background="{TemplateBinding Background}">
                        <Path x:Name="ExpandPath"
                              Margin="1,1,1,1"
                              HorizontalAlignment="Left"
                              VerticalAlignment="Center"
                              Data="M 0 2 L 0 3 L 2 3 L 2 5 L 3 5 L 3 3 L 5 3 L 5 2 L 3 2 L 3 0 L 2 0 L 2 2 Z"
                              Fill="{StaticResource GlyphBrush}"
                              Visibility="Collapsed" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="ExpandPath" Property="Data" Value="M 0 2 L 0 3 L 5 3 L 5 2 Z" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="TreeView_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="black" />
        <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}" />
        <Setter Property="IsExpanded" Value="{Binding .IsExpanded, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        <Setter Property="IsSelected" Value="{Binding .IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid Background="Transparent">
                        <!--
                            <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" MinWidth="15" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                        -->
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <StackPanel Grid.Row="0" Orientation="Horizontal">
                            <ToggleButton x:Name="Expander"
                                          Grid.Column="0"
                                          Width="11"
                                          Height="11"
                                          Margin="2,0,0,0"
                                          Background="{DynamicResource Level1Expand}"
                                          BorderBrush="Transparent"
                                          ClickMode="Press"
                                          IsChecked="{Binding Path=IsExpanded,
                                                              RelativeSource={RelativeSource TemplatedParent}}"
                                          Style="{StaticResource ImageToggleStyle}" />
                            <!--
                                <ToggleButton x:Name="Expander"
                                ClickMode="Press"
                                Background="{DynamicResource Level1NotExpand}"
                                IsChecked="{Binding IsExpanded,
                                RelativeSource={RelativeSource TemplatedParent}}"
                                Style="{StaticResource ExpandCollapseToggleStyle}" />
                            -->
                            <!--  暂时使用原来菜单expender样式  -->
                            <!--  Style="{StaticResource ExpandCollapseToggleStyle}" />  -->
                            <Border x:Name="Bd"
                                    Grid.Column="1"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}"
                                    SnapsToDevicePixels="true">
                                <StackPanel Margin="2" Orientation="Horizontal">
                                    <ContentPresenter x:Name="PART_Header"
                                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                      ContentSource="Header"
                                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                </StackPanel>
                            </Border>
                        </StackPanel>
                        <ItemsPresenter x:Name="ItemsHost"
                                        Grid.Row="1"
                                        Grid.Column="0"
                                        Grid.ColumnSpan="3"
                                        Margin="{Binding Converter={StaticResource mtidc}}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="false">
                            <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed" />
                            <Setter Property="Foreground" Value="#2F3B74" />
                            <Setter Property="FontWeight" Value="Normal" />
                            <Setter TargetName="Expander" Property="Background" Value="{DynamicResource Level1NotExpand}" />
                        </Trigger>
                        <Trigger Property="HasItems" Value="false">
                            <Setter TargetName="Expander" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Foreground" Value="black" />
                            <Setter TargetName="Bd" Property="Background" Value="{DynamicResource StyleNumber1_SelectedBrush}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Cursor" Value="Hand" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="HasItems" Value="true" />
                                <Condition Property="IsExpanded" Value="true" />
                            </MultiTrigger.Conditions>
                            <!--  <Setter TargetName="Bd" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />  -->
                            <Setter Property="FontWeight" Value="Bold" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="true" />
                                <Condition Property="IsSelectionActive" Value="false" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="Bd" Property="Background" Value="{DynamicResource StyleNumber1_SelectedBrush}" />
                            <Setter Property="Foreground" Value="Black" />
                        </MultiTrigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </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>