<UserControl x:Class="Platform.Controls.ComponentContainer.DataBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:base="clr-namespace:Platform.Controls.BaseContainer"
             xmlns:controlHelper="clr-namespace:Platform.Controls.ControlsHelper"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:dhcc="http://www.dhcc.com.cn"
             xmlns:helper="clr-namespace:Platform.Controls.ControlsHelper"
             xmlns:local="clr-namespace:Platform.Controls.ComponentContainer"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
             xmlns:table="clr-namespace:Platform.Controls.TableContainer"
             x:Name="dataBox"
             Height="300"
             MinHeight="150"
             HorizontalAlignment="Stretch"
             d:DesignHeight="300"
             d:DesignWidth="600"
             mc:Ignorable="d">
    <UserControl.Resources>
        <Storyboard x:Key="OnMouseEnter1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="textBlock" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="90" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="OnMouseLeave1">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="textBlock" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="-90" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <ContextMenu x:Key="menuFilter" dhcc:FocusManager.OnlyMouseControlHandled="{x:Static dhcc:ControlHelper.EmptyMouseHandled}" />

        <dhcc:BoolToVisibilityConverter x:Key="BoolToVisibility" />

        <DataGridTemplateColumn x:Key="RadioColumn" Visibility="{Binding IsShowRadioColumn, ElementName=dataBox, Converter={StaticResource BoolToVisibility}}" />

        <DataTemplate x:Key="RadioButtonColumn">
            <RadioButton HorizontalAlignment="Center"
                         VerticalAlignment="Center"
                         dhcc:FocusManager.OnlyMouseControlHandled="{x:Static dhcc:ControlHelper.EmptyMouseHandled}"
                         IsChecked="{Binding IsSelected,
                                             RelativeSource={RelativeSource AncestorType=DataGridRow,
                                                                            Mode=FindAncestor}}"
                         Style="{x:Null}" />
        </DataTemplate>

        <DataTemplate x:Key="CheckBoxColumn">
            <CheckBox x:Name="cellCheckBox"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Checked="cellCheckBox_CheckedChanged"
                      dhcc:FocusManager.OnlyMouseControlHandled="{x:Static dhcc:ControlHelper.EmptyMouseHandled}"
                      IsChecked="{Binding Path=(helper:DataGridHelper.IsChecked),
                                          RelativeSource={RelativeSource AncestorType=DataGridRow,
                                                                         Mode=FindAncestor}}"
                      Style="{x:Null}"
                      Unchecked="cellCheckBox_CheckedChanged" />
        </DataTemplate>

        <DataTemplate x:Key="CheckBoxColumnHeader">
            <CheckBox x:Name="headerCheckBox"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Checked="headerCheckBox_Checked"
                      dhcc:FocusManager.OnlyMouseControlHandled="{x:Static dhcc:ControlHelper.EmptyMouseHandled}"
                      IsChecked="{Binding Path=(helper:DataGridHelper.IsChecked),
                                          ElementName=dhccDataGrid}"
                      Style="{x:Null}"
                      Unchecked="headerCheckBox_Unchecked" />
        </DataTemplate>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid Margin="0,0,0,3">
            <Grid.Resources>



                <LinearGradientBrush x:Key="TextBoxBorder" MappingMode="Absolute" StartPoint="0,0" EndPoint="0,20">
                    <GradientStop Offset="0.05" Color="#ABADB3" />
                    <GradientStop Offset="0.07" Color="#E2E3EA" />
                    <GradientStop Offset="1" Color="#E3E9EF" />
                </LinearGradientBrush>

                <!--  TextBoxFilter  -->
                <Style x:Key="TextBoxFilter"
                       BasedOn="{StaticResource {x:Type TextBox}}"
                       TargetType="{x:Type TextBox}">
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
                    <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
                    <Setter Property="BorderThickness" Value="1" />
                    <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}" />
                    <Setter Property="AllowDrop" Value="true" />
                    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type TextBox}">
                                <Microsoft_Windows_Themes:ListBoxChrome x:Name="Bd"
                                                                        Background="{TemplateBinding Background}"
                                                                        BorderBrush="{TemplateBinding BorderBrush}"
                                                                        BorderThickness="{TemplateBinding BorderThickness}"
                                                                        RenderFocused="{TemplateBinding IsKeyboardFocusWithin}"
                                                                        RenderMouseOver="{TemplateBinding IsMouseOver}"
                                                                        SnapsToDevicePixels="true">

                                    <ScrollViewer x:Name="PART_ContentHost"
                                                  Margin="18,0,18,0"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

                                </Microsoft_Windows_Themes:ListBoxChrome>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsEnabled" Value="false">
                                        <Setter TargetName="Bd" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <!--  TextBoxFilter  -->
                <!--  ComboBoxItem  -->
                <Style TargetType="{x:Type ComboBoxItem}">
                    <Setter Property="SnapsToDevicePixels" Value="true" />
                    <Setter Property="OverridesDefaultStyle" Value="true" />
                    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                    <Setter Property="Cursor" Value="Hand" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ComboBoxItem">
                                <Border Name="Border"
                                        dhcc:FocusManager.OnlyMouseControlHandled="{x:Static dhcc:ControlHelper.EmptyMouseHandled}"
                                        Padding="2"
                                        SnapsToDevicePixels="true">
                                    <ContentPresenter />
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsHighlighted" Value="true">
                                        <Setter TargetName="Border" Property="Background" Value="{DynamicResource ComboBoxItem_Select_Background}" />
                                    </Trigger>
                                    <Trigger Property="IsEnabled" Value="false">
                                        <Setter Property="Foreground" Value="{DynamicResource ComboBoxItem_Enable_Foreground}" />
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <!--  ComboBoxItem  -->

                <!--  ComBoxFilter  -->
                <Style x:Key="ComboBoxFilter"
                       BasedOn="{StaticResource {x:Type ComboBox}}"
                       TargetType="{x:Type ComboBox}">
                    <Setter Property="Width" Value="22" />
                    <Setter Property="Height" Value="22" />
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                    <Setter Property="Padding" Value="1" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ComboBox}">
                                <Grid x:Name="RootElement" MinWidth="100">
                                    <Grid.Resources>
                                        <Style x:Key="ToggleButtonFilter" TargetType="{x:Type ToggleButton}">
                                            <Setter Property="Width" Value="22" />
                                            <Setter Property="Height" Value="22" />
                                            <Setter Property="Cursor" Value="Hand" />
                                            <Setter Property="HorizontalAlignment" Value="Left" />
                                            <Setter Property="VerticalAlignment" Value="Center" />
                                            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                                            <Setter Property="Padding" Value="1" />
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                        <Grid>
                                                            <Rectangle Margin="2"
                                                                       Fill="Transparent"
                                                                       RadiusX="2.5"
                                                                       RadiusY="2.5"
                                                                       Stroke="#FF000000"
                                                                       StrokeThickness="0" />
                                                            <Ellipse Width="10"
                                                                     Height="10"
                                                                     Margin="0,4,5,0"
                                                                     HorizontalAlignment="Right"
                                                                     VerticalAlignment="Top"
                                                                     Stroke="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"
                                                                     StrokeThickness="2" />
                                                            <Path Width="7"
                                                                  Height="7"
                                                                  Margin="0,7,7,0"
                                                                  Data="M0,0 L1,-1"
                                                                  Fill="Black"
                                                                  Stretch="Fill"
                                                                  Stroke="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"
                                                                  StrokeThickness="2" />
                                                            <Path x:Name="path"
                                                                  Width="6"
                                                                  Height="6"
                                                                  Margin="0,0,2,0"
                                                                  HorizontalAlignment="Right"
                                                                  VerticalAlignment="Bottom"
                                                                  Data="M0,0L6,0 3,3z"
                                                                  Fill="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
                                                        </Grid>
                                                        <ControlTemplate.Triggers>
                                                            <Trigger Property="IsChecked" Value="true">
                                                                <Setter TargetName="path" Property="Visibility" Value="Collapsed" />
                                                            </Trigger>
                                                            <Trigger Property="IsChecked" Value="false">
                                                                <Setter TargetName="path" Property="Visibility" Value="Visible" />
                                                            </Trigger>
                                                        </ControlTemplate.Triggers>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </Grid.Resources>
                                    <Popup x:Name="PART_Popup"
                                           Grid.ColumnSpan="2"
                                           Margin="1"
                                           AllowsTransparency="true"
                                           IsOpen="{Binding IsDropDownOpen,
                                                            RelativeSource={RelativeSource TemplatedParent}}"
                                           Placement="Bottom"
                                           PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
                                        <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw"
                                                                                         MinWidth="{Binding ActualWidth,
                                                                                                            ElementName=RootElement}"
                                                                                         MaxHeight="{TemplateBinding MaxDropDownHeight}"
                                                                                         Color="Transparent">
                                            <Border x:Name="DropDownBorder"
                                                    Background="{DynamicResource ComboBoxDropdown_Normal_Background}"
                                                    BorderBrush="{DynamicResource ComboBoxDropdown_Normal_BorderBrush}"
                                                    BorderThickness="{DynamicResource ComboBoxDropdown_Normal_BorderThickness}"
                                                    CornerRadius="3"
                                                    Focusable="False">
                                                <Grid>
                                                    <Grid.Resources>
                                                        <Style x:Key="SeparatorLineStyle" TargetType="{x:Type Line}">
                                                            <Setter Property="X2" Value="1" />
                                                            <Setter Property="Height" Value="1" />
                                                            <Setter Property="Stretch" Value="Fill" />
                                                            <Setter Property="StrokeEndLineCap" Value="Square" />
                                                            <Setter Property="StrokeStartLineCap" Value="Square" />
                                                            <Setter Property="StrokeThickness" Value="{Binding Height, RelativeSource={RelativeSource Self}}" />
                                                            <Setter Property="Stroke" Value="{DynamicResource ComboBoxDropdown_Normal_BorderBrush}" />
                                                        </Style>
                                                        <Style TargetType="{x:Type ListBoxItem}">
                                                            <Setter Property="Template">
                                                                <Setter.Value>
                                                                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                                                        <CheckBox Content="{TemplateBinding Content}"
                                                                                  ContentTemplate="{TemplateBinding ContentTemplate}"
                                                                                  ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                                                                  dhcc:FocusManager.OnlyMouseControlHandled="{x:Static dhcc:ControlHelper.EmptyMouseHandled}"
                                                                                  FocusVisualStyle="{TemplateBinding FocusVisualStyle}"
                                                                                  IsChecked="{Binding IsSelected,
                                                                                                      RelativeSource={RelativeSource TemplatedParent}}"
                                                                                  Style="{x:Null}" />
                                                                    </ControlTemplate>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Style>
                                                    </Grid.Resources>
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="Auto" />
                                                        <RowDefinition Height="*" />
                                                    </Grid.RowDefinitions>

                                                    <CheckBox x:Name="chbxAll"
                                                              Margin="2"
                                                              Checked="chbxAll_Checked"
                                                              Content="全选"
                                                              dhcc:FocusManager.OnlyMouseControlHandled="{x:Static dhcc:ControlHelper.EmptyMouseHandled}"
                                                              Style="{x:Null}"
                                                              Unchecked="chbxAll_Unchecked" />

                                                    <Line Grid.Row="1" Style="{StaticResource SeparatorLineStyle}" />
                                                    <ListBox Name="checkListBox"
                                                             Grid.Row="2"
                                                             Margin="2"
                                                             BorderThickness="0"
                                                             SelectionChanged="checkListBox_SelectionChanged"
                                                             SelectionMode="Multiple"
                                                             Style="{x:Null}" />
                                                </Grid>

                                            </Border>
                                        </Microsoft_Windows_Themes:SystemDropShadowChrome>
                                    </Popup>
                                    <ToggleButton Grid.ColumnSpan="2"
                                                  Background="{DynamicResource ComboBox_Normal_Background}"
                                                  BorderBrush="#FFBCBDBD"
                                                  BorderThickness="1"
                                                  ClickMode="Press"
                                                  Focusable="false"
                                                  IsChecked="{Binding Path=IsDropDownOpen,
                                                                      Mode=TwoWay,
                                                                      RelativeSource={RelativeSource TemplatedParent}}"
                                                  Style="{StaticResource ToggleButtonFilter}" />

                                </Grid>


                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <!--  ComBoxFilter  -->

                <!--  ButtonClear  -->
                <Style x:Key="ButtonClear"
                       BasedOn="{StaticResource {x:Type Button}}"
                       TargetType="{x:Type Button}">
                    <Setter Property="Margin" Value="0" />
                    <Setter Property="Width" Value="22" />
                    <Setter Property="Height" Value="22" />
                    <Setter Property="Cursor" Value="Hand" />
                    <Setter Property="HorizontalAlignment" Value="Right" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                    <Setter Property="Padding" Value="1" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <TextBlock x:Name="textBlock"
                                           HorizontalAlignment="Center"
                                           VerticalAlignment="Center"
                                           Cursor="Hand"
                                           FontFamily="Bodoni MT Black"
                                           FontSize="18"
                                           FontWeight="Bold"
                                           Foreground="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"
                                           RenderTransformOrigin="0.5,0.5"
                                           Text="×"
                                           ToolTip="关闭">
                                    <TextBlock.RenderTransform>
                                        <TransformGroup>
                                            <ScaleTransform />
                                            <SkewTransform />
                                            <RotateTransform />
                                            <TranslateTransform />
                                        </TransformGroup>
                                    </TextBlock.RenderTransform>
                                </TextBlock>
                                <ControlTemplate.Triggers>
                                    <EventTrigger RoutedEvent="Mouse.MouseEnter">
                                        <BeginStoryboard Storyboard="{StaticResource OnMouseEnter1}" />
                                    </EventTrigger>
                                    <EventTrigger RoutedEvent="Mouse.MouseLeave">
                                        <BeginStoryboard Storyboard="{StaticResource OnMouseLeave1}" />
                                    </EventTrigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
                <!--  ButtonClear  -->
            </Grid.Resources>
            <TextBox x:Name="txtFilter"
                     Grid.Column="1"
                     Width="Auto"
                     HorizontalAlignment="Stretch"
                     VerticalContentAlignment="Center"
                     controlHelper:TextBoxHelper.Placeholder="请输入筛选条件…"
                     controlHelper:TextBoxHelper.PlaceholderOffset="23,5"
                     Style="{StaticResource TextBoxFilter}"
                     TextChanged="txt_TextChanged"
                     Visibility="{Binding IsShowSelectBar,
                                          ElementName=dataBox,
                                          Converter={StaticResource BoolToVisibility}}" />
            <ComboBox x:Name="cbxFilter"
                      Style="{StaticResource ComboBoxFilter}"
                      Visibility="{Binding IsShowSelectBar,
                                           ElementName=dataBox,
                                           Converter={StaticResource BoolToVisibility}}" />

            <Button x:Name="btnClear"
                    Click="btnClear_Click"
                    Style="{StaticResource ButtonClear}"
                    Visibility="Collapsed" />
        </Grid>
        <table:DHCCDataGrid x:Name="dhccDataGrid"
                            Grid.Row="1"
                            Height="Auto"
                            MinHeight="150"
                            MaxHeight="1000"
                            dhcc:FocusManager.LostFocus="dhccDataGrid_LostFocus"
                            IsReadOnly="True"
                            SelectionMode="Single" />
        <Grid Grid.Row="2" DataContext="{Binding Path=., ElementName=dataBox}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <local:DataPager x:Name="dataPager"
                             Margin="3"
                             dhcc:FocusManager.OnlyMouseControlHandled="{x:Static helper:ControlHelper.EmptyMouseHandled}"
                             PageChanged="dataPager_PageChanged"
                             PageSizeList="{Binding PageSizeLis}"
                             Total="{Binding Total}"
                             Visibility="{Binding IsShowPageBar,
                                                  Converter={StaticResource BoolToVisibility}}" />

            <StackPanel x:Name="Operator"
                        Grid.Column="1"
                        Orientation="Horizontal">
                <base:ImageButton x:Name="btnPrint"
                                  Margin="3"
                                  GrayImageSource="/Platform.Controls;component/Resource/pagination_loading.gif"
                                  ImageSource="/Platform.Controls;component/Resource/FilePrint.png"
                                  ToolTip="打印"
                                  Visibility="{Binding IsShowPrintButton,
                                                       Converter={StaticResource BoolToVisibility}}" />
                <base:ImageButton x:Name="btnExport"
                                  Margin="3"
                                  GrayImageSource="/Platform.Controls;component/Resource/pagination_loading.gif"
                                  ImageSource="/Platform.Controls;component/Resource/MenuTree_TradeSelected.png"
                                  ToolTip="导出"
                                  Visibility="{Binding IsShowExportButton,
                                                       Converter={StaticResource BoolToVisibility}}" />
            </StackPanel>
        </Grid>

    </Grid>
</UserControl>
