<UserControl x:Class="Platform.Controls.TableContainer.DHCCTreeViewList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:Platform.Controls.TableContainer"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"             
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             x:Name="this"
             MinWidth="500"
             MinHeight="300"          
             mc:Ignorable="d">
    
    <UserControl.Resources>
        <Style x:Key="TBHelpStyle" TargetType="TextBlock">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Width" Value="16" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="Text" Value="?" />
            <Setter Property="TextAlignment" Value="Center" />
            <Setter Property="FontWeight" Value="ExtraBold" />
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1.5">
                        <GradientBrush.GradientStops>
                            <GradientStopCollection>
                                <GradientStop Offset="0" Color="#FF5F8699" />
                                <GradientStop Offset="1" Color="#FF000000" />
                            </GradientStopCollection>
                        </GradientBrush.GradientStops>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>
        <VisualBrush x:Key="SelectBoxBrush"
                     AlignmentX="Left"
                     Stretch="None"
                     TileMode="None">
            <VisualBrush.Visual>
                <TextBlock FontStyle="Italic"
                           Foreground="Gray"
                           Text="请输入筛选条件…" />
            </VisualBrush.Visual>
        </VisualBrush>

        <!--  颜色与画刷  -->
        <Color x:Key="ControlMouseOverColor">#FF3843C4</Color>
        <Color x:Key="ControlPressedColor">red</Color>
        <Color x:Key="ContentAreaColorLight">White</Color>
        <Color x:Key="DatagridCurrentCellBorderColor">#F8F8F8</Color>
        <Color x:Key="ContentAreaColorDark">White</Color>
        <Color x:Key="ControlMediumColor">#B4C8D5</Color>
        <Color x:Key="ControlDarkColor">#B4C8D5</Color>
        <Color x:Key="ControlLightColor">#F8F8F8</Color>
        <SolidColorBrush x:Key="DataGridBorderBackground" Color="#F8F8F8" />
        <SolidColorBrush x:Key="DataGridBorderBrush" Color="#75A1AE" />
        <SolidColorBrush x:Key="DataGridColumnHeader_BorderBrush" Color="#6D9CAA" />
        <LinearGradientBrush x:Key="DataGridColumnHeadersPresenter_Background" StartPoint="0.5,1" EndPoint="0.5,0">
            <GradientStop Offset="0" Color="#BBD6EF" />
            <GradientStop Offset="0.5" Color="#90B6C4" />
            <GradientStop Offset="0.5" Color="#C5D9E0" />
            <GradientStop Offset="1" Color="#FFFFFF" />
        </LinearGradientBrush>
        <!--  颜色与画刷end  -->

        <!--  树  -->
        <Style TargetType="{x:Type local:TreeViewList}">
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="BorderBrush" Value="{StaticResource DataGridBorderBrush}" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
            <Setter Property="Background" Value="{StaticResource DataGridBorderBackground}" />
            <Setter Property="AlternationCount" Value="2" />
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <HierarchicalDataTemplate ItemsSource="{Binding Children}" />
                </Setter.Value>
            </Setter>
            <!--  <Setter Property="FocusVisualStyle" Value="{x:Null}" />  -->
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:TreeViewList}">
                        <Border BorderBrush="{StaticResource DataGridBorderBrush}" BorderThickness="1,0,1,1">
                            <DockPanel>
                                <GridViewHeaderRowPresenter Columns="{Binding Columns, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TreeViewList}}" DockPanel.Dock="Top" />

                                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                                    <ItemsPresenter VerticalAlignment="Top" />
                                </ScrollViewer>
                            </DockPanel>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <!--  树end  -->

        <!--  头部标题样式  -->
        <Style TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="FontFamily" Value="宋体" />
            <Setter Property="FontSize" Value="12" />
            <Setter Property="Foreground" Value="Black" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="BorderBrush" Value="{StaticResource DataGridColumnHeader_BorderBrush}" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="BorderThickness" Value="0,0,1,1" />
            <Setter Property="Height" Value="27" />
            <Setter Property="Background" Value="{StaticResource DataGridColumnHeadersPresenter_Background}" />
            <!--
                <Setter Property="Template">
                <Setter.Value>
                <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                <Grid>
                <Border x:Name="columnHeaderBorder"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                Padding="3">
                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                </Border>
                
                <Thumb x:Name="PART_LeftHeaderGripper"
                HorizontalAlignment="Left"
                Style="{StaticResource ColumnHeaderGripperStyle}" />
                <Thumb x:Name="PART_RightHeaderGripper"
                HorizontalAlignment="Right"
                Style="{StaticResource ColumnHeaderGripperStyle}" />
                </Grid>
                </ControlTemplate>
                </Setter.Value>
                </Setter>
            -->


        </Style>
        <!--  头部标题样式end  -->

        <!--  树项  -->
        <Style TargetType="{x:Type local:TreeViewListItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:TreeViewListItem}">
                        <StackPanel>
                            <Border x:Name="Bd"
                                    Height="23"
                                    Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="{TemplateBinding Padding}">
                                <Border x:Name="InnerBd" BorderThickness="0">
                                    <GridViewRowPresenter x:Name="PART_Header"
                                                          Columns="{Binding Columns,
                                                                            RelativeSource={RelativeSource Mode=FindAncestor,
                                                                                                           AncestorType=local:TreeViewList}}"
                                                          Content="{TemplateBinding Header}" />
                                </Border>
                            </Border>
                            <ItemsPresenter x:Name="ItemsHost" />
                        </StackPanel>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsExpanded" Value="false">
                                <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed" />
                            </Trigger>

                            <Trigger SourceName="Bd" Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="BorderThickness" Value="0,1,0,1" />
                                <Setter TargetName="Bd" Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                            <GradientStop Offset="0" Color="{DynamicResource ControlLightColor}" />
                                            <GradientStop Offset="1" Color="{DynamicResource ControlMediumColor}" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="BorderBrush" Value="#83B5D0" />
                                <Setter TargetName="InnerBd" Property="BorderBrush">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                            <GradientStop Offset="0" Color="#FFFCFDFE" />
                                            <GradientStop Offset="1" Color="#FFF2F7FE" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter TargetName="Bd" Property="BorderThickness" Value="0,1,0,1" />
                                <Setter TargetName="Bd" Property="Background" Value="#B4C8D5" />
                                <Setter TargetName="Bd" Property="BorderBrush" Value="#83B5D0" />
                                <Setter Property="BorderBrush" Value="#B4C8D5" />
                                <Setter TargetName="InnerBd" Property="BorderBrush">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                            <GradientStop Offset="0" Color="#FFF2F8FF" />
                                            <GradientStop Offset="1" Color="#FFDFEEFF" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true" />
                                    <Condition Property="IsSelectionActive" Value="false" />
                                </MultiTrigger.Conditions>
                                <Setter TargetName="Bd" Property="Background">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                            <GradientStop Offset="0" Color="#FFF9F9F9" />
                                            <GradientStop Offset="1" Color="#FFE6E6E6" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="BorderBrush" Value="#FFDADADA" />
                                <Setter TargetName="InnerBd" Property="BorderBrush">
                                    <Setter.Value>
                                        <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                            <GradientStop Offset="0" Color="#FFFBFBFC" />
                                            <GradientStop Offset="1" Color="#FFF1F1F1" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </MultiTrigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>

        </Style>
        <!--  树项end  -->

        <!--  缩进  -->
        <local:LevelToIndentConverter x:Key="LevelToIndentConverter" />
        <!--  缩进end  -->

        <!--  展开按钮  -->
        <StreamGeometry x:Key="TreeArrow">M0.5,0L0.5,7 4.5,3.5z</StreamGeometry>
        <Style x:Key="ExpandCollapseToggleStyle_1" TargetType="{x:Type ToggleButton}">
            <Setter Property="Focusable" Value="False" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Border Background="Transparent">
                            <Path x:Name="ExpandPath"
                                  Margin="0,2,5,0"
                                  HorizontalAlignment="Right"
                                  VerticalAlignment="Center"
                                  Data="{StaticResource TreeArrow}"
                                  Fill="Transparent"
                                  Stroke="#FF989898" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="ExpandPath" Property="RenderTransform">
                                    <Setter.Value>
                                        <RotateTransform Angle="45" CenterX="0" CenterY="2.5" />
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="ExpandPath" Property="Fill" Value="#FF595959" />
                                <Setter TargetName="ExpandPath" Property="Stroke" Value="#FF262626" />
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="ExpandPath" Property="Stroke" Value="#FF1BBBFA" />
                                <Setter TargetName="ExpandPath" Property="Fill" Value="Transparent" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Effect">
                        <Setter.Value>
                            <DropShadowEffect BlurRadius="5"
                                              ShadowDepth="0"
                                              Color="#FF2CC8F8" />
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="ExpandCollapseToggleStyle_2" TargetType="{x:Type ToggleButton}">
            <Setter Property="Focusable" Value="False" />
            <Setter Property="Width" Value="19" />
            <Setter Property="Height" Value="13" />
            <Setter Property="Cursor" Value="Hand" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Border Width="19"
                                Height="13"
                                Background="Transparent">
                            <Border Width="9"
                                    Height="9"
                                    Margin="0,-5,0,0"
                                    BorderBrush="#FF1898B5"
                                    BorderThickness="1"
                                    CornerRadius="1"
                                    SnapsToDevicePixels="True">
                                <Border.Background>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                        <LinearGradientBrush.GradientStops>
                                            <GradientStop Offset=".2" Color="White" />
                                            <GradientStop Offset="1" Color="#ffc0B7A6" />
                                        </LinearGradientBrush.GradientStops>
                                    </LinearGradientBrush>
                                </Border.Background>
                                <Path x:Name="ExpandPath"
                                      Margin="1,1,1,1"
                                      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="Black" />
                            </Border>
                        </Border>
                        <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>
        <!--  展开按钮end  -->

        <!--  行号及展开按钮  -->
        <DataTemplate x:Key="CellTemplate_Name">
            <DockPanel>
                <ToggleButton x:Name="Expander"
                              Margin="{Binding Level,
                                               Converter={StaticResource LevelToIndentConverter},
                                               RelativeSource={RelativeSource AncestorType={x:Type local:TreeViewListItem}}}"
                              ClickMode="Press"
                              IsChecked="{Binding Path=IsExpanded,
                                                  RelativeSource={RelativeSource AncestorType={x:Type local:TreeViewListItem}}}"
                              Style="{StaticResource ExpandCollapseToggleStyle_1}" />
                <TextBlock Text="{Binding No}" />
            </DockPanel>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=HasItems, RelativeSource={RelativeSource AncestorType={x:Type local:TreeViewListItem}}}" Value="False">
                    <Setter TargetName="Expander" Property="Visibility" Value="Hidden" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        <DataTemplate x:Key="CellTemplate_Name2">
            <DockPanel>
                <ToggleButton x:Name="Expander"
                              Margin="{Binding Level,
                                               Converter={StaticResource LevelToIndentConverter},
                                               RelativeSource={RelativeSource AncestorType={x:Type local:TreeViewListItem}}}"
                              ClickMode="Press"
                              IsChecked="{Binding Path=IsExpanded,
                                                  RelativeSource={RelativeSource AncestorType={x:Type local:TreeViewListItem}}}"
                              Style="{StaticResource ExpandCollapseToggleStyle_2}" />
                <TextBlock Text="{Binding No}" />
            </DockPanel>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=HasItems, RelativeSource={RelativeSource AncestorType={x:Type local:TreeViewListItem}}}" Value="False">
                    <Setter TargetName="Expander" Property="Visibility" Value="Hidden" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
        <!--  行号及展开按钮end  -->
    </UserControl.Resources>
    <Border Background="#FFF5F6F5" BorderThickness="0">
        <Grid Name="GridDataBox">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid Name="GridSelectBar" Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="40" />
                    <ColumnDefinition Width="50" />
                    <ColumnDefinition Width="20" />
                </Grid.ColumnDefinitions>
                <TextBox Name="txtSelect"
                         Height="23"
                         VerticalContentAlignment="Center">
                    <TextBox.Style>
                        <Style TargetType="TextBox">
                            <Style.Triggers>
                                <Trigger Property="Text" Value="{x:Null}">
                                    <Setter Property="Background" Value="{StaticResource SelectBoxBrush}" />
                                </Trigger>
                                <Trigger Property="Text" Value="">
                                    <Setter Property="Background" Value="{StaticResource SelectBoxBrush}" />
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </TextBox.Style>
                </TextBox>

                <TextBlock Grid.Column="1"
                           VerticalAlignment="Center"
                           Text="行数:"
                           TextAlignment="Right" />
                <TextBox Name="txtRowNum"
                         Grid.Column="2"
                         Width="50"
                         Height="23"
                         Margin="0,0,10,0"
                         VerticalContentAlignment="Center" />
                <TextBlock Name="tbHelp"
                           Grid.Column="3"
                           VerticalAlignment="Center"
                           Style="{StaticResource TBHelpStyle}" />
                <Popup x:Name="popHelp"
                       AllowsTransparency="True"
                       Placement="Left"
                       PlacementTarget="{Binding ElementName=tbHelp}"
                       PopupAnimation="Fade"
                       StaysOpen="False">
                    <Border BorderBrush="#FF000000"
                            BorderThickness="1"
                            CornerRadius="5">
                        <Border.Background>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1.5">
                                <GradientBrush.GradientStops>
                                    <GradientStopCollection>
                                        <GradientStop Offset="0" Color="#FF5F8699" />
                                        <GradientStop Offset="1" Color="#FFF" />
                                    </GradientStopCollection>
                                </GradientBrush.GradientStops>
                            </LinearGradientBrush>
                        </Border.Background>
                        <TextBlock Margin="8">
                            <StackPanel>
                                <TextBlock Margin="0,2" Text="有选择框时，空格键选中或取消" />
                                <TextBlock Margin="0,2" Text="无选择框时，回车键选中并退出" />
                                <TextBlock Margin="0,2" Text="上下键可以滚动行和翻页" />
                                <TextBlock Margin="0,2" Text="首  页：">
                                    <TextBlock Name="tbHome" />
                                </TextBlock>
                                <TextBlock Margin="0,2" Text="上一页：">
                                    <TextBlock Name="tbUp" />
                                </TextBlock>
                                <TextBlock Margin="0,2" Text="下一页：">
                                    <TextBlock Name="tbNext" />
                                </TextBlock>
                                <TextBlock Margin="0,2" Text="尾  页：">
                                    <TextBlock Name="tbEnd" />
                                </TextBlock>
                                <TextBlock Margin="0,2" Text="打  印：">
                                    <TextBlock Name="tbPrint" />
                                </TextBlock>
                            </StackPanel>
                        </TextBlock>
                    </Border>
                </Popup>
            </Grid>
            <local:TreeViewList x:Name="treeViewList"
                                   Grid.Row="1"
                                   MinHeight="145"
                                   MaxHeight="700">
                <local:TreeViewList.Columns>
                    <!--
                        <GridViewColumn Width="120" Header="pk"
                        CellTemplate="{StaticResource CellTemplate_Name}"
                        DisplayMemberBinding="{Binding pk}"
                        >
                        </GridViewColumn>
                        <GridViewColumn Header="name"
                        Width="222" >
                        <GridViewColumn.CellTemplate>
                        <DataTemplate>
                        <TextBlock HorizontalAlignment="Stretch"
                        Text="{Binding name}" />
                        </DataTemplate>
                        </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        
                        <GridViewColumn Width="120" Header="fk">
                        <GridViewColumn.CellTemplate>
                        <DataTemplate>
                        <TextBlock HorizontalAlignment="Stretch" Text="{Binding fk}" />
                        </DataTemplate>
                        </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    -->
                </local:TreeViewList.Columns>
            </local:TreeViewList>
            <Border Name="BorderPage"
                    Grid.Row="2"
                    BorderBrush="Gray"
                    BorderThickness="1"
                    CornerRadius="5"
                    Padding="1">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="70" />
                    </Grid.ColumnDefinitions>
                    <StackPanel Grid.Column="0"
                                Margin="5,0"
                                Orientation="Horizontal">
                        <TextBlock VerticalAlignment="Center" Text="页码：" />
                        <TextBlock Name="tbkCurrent"
                                   VerticalAlignment="Center"
                                   Text="1" />
                        <TextBlock VerticalAlignment="Center" Text="/" />
                        <TextBlock Name="tbkTotal"
                                   VerticalAlignment="Center"
                                   Text="1" />
                        <TextBlock Margin="20,0,0,0"
                                   VerticalAlignment="Center"
                                   Text="转到" />
                        <TextBox Name="txtPageNum"
                                 Width="50"
                                 Height="20"
                                 VerticalContentAlignment="Center" />
                        <TextBlock VerticalAlignment="Center" Text="页" />
                        <Button Name="btnHome"
                                Width="55"
                                Height="23"
                                Margin="20,0,2,0"
                                Content="首  页" />
                        <Button Name="btnUp"
                                Width="55"
                                Height="23"
                                Margin="2,0"
                                Content="上一页" />
                        <Button Name="btnNext"
                                Width="55"
                                Height="23"
                                Margin="2,0"
                                Content="下一页" />
                        <Button Name="btnEnd"
                                Width="55"
                                Height="23"
                                Margin="2,0"
                                Content="尾  页" />
                    </StackPanel>
                    <Button Name="btnPrint"
                            Grid.Column="1"
                            Width="55"
                            Height="23"
                            Content="打  印" />

                </Grid>
            </Border>
        </Grid>
    </Border>
</UserControl>

