<ResourceDictionary x:Class="FSI.Lib.Wpf.Ctrls.FilterDataGrid.FilterDataGridDictionary"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:control="clr-namespace:FSI.Lib.Wpf.Ctrls.FilterDataGrid"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib">

    <!--  STRING FORMAT CONVERTER  -->
    <control:StringFormatConverter x:Key="StringFormatConverter" />

    <!--  INITIAL POPUP SIZE  -->
    <sys:Double x:Key="PopupHeight">420</sys:Double>
    <sys:Double x:Key="PopupWidth">262</sys:Double>
    <sys:Boolean x:Key="StayOpen">False</sys:Boolean>

    <!--  https://yqnn.github.io/svg-path-editor/  -->

    <!--  FILTER SET ICON  -->
    <Geometry x:Key="FilterSet">
        M 0 17 H 12 L 6 25 Z M 6 0 H 29 L 29 3 L 20 10 L 20 21 H 15 L 15 10 L 6 3 Z
    </Geometry>

    <!--  FILTER BUTTON ICON  -->
    <Geometry x:Key="Filter">
        M 7 10 L 12 15 L 17 10 H 7 Z
    </Geometry>

    <!--  DELETE FILTER ICON  -->
    <Geometry x:Key="FilterDelete">
        M11.1 11.4L8.5 8.9L9.8 7.6L12.3 10.1L14.8 7.6L16.1 8.9L13.6 11.4L16.1 13.9L14.8 15.2L12.3 12.6L9.8 15.2L8.5 13.9ZM0 0H13L13 2L8 6V14L5 11V6L0 2Z
    </Geometry>

    <!--  BOX CHECKED ICON  -->
    <Geometry x:Key="FilterChecked">
        M 125 125 L 0 125 V 0 H 125 Z M 1 124 H 124 V 1 H 1 Z M 20 68 L 29 57 L 56 80 L 98 25 L 110 35 L 59 101 Z
    </Geometry>

    <!--  GRIPSIZE ICON  -->
    <Geometry x:Key="GripSizeIcon">
        M0 9L2 9M4 9L6 9M8 9L10 9M1 8L1 10M5 8L5 10M9 8L9 10M4 5L6 5M8 5L10 5M5 4L5 6M9 4L9 6M8 1L10 1M9 0L9 2
    </Geometry>

    <!--  SEARCH MAGNIFIER ICON  -->
    <Geometry x:Key="Magnifier">
        M9.6 8.5H9L8.7 8.2C9.6 7.4 10 6.2 10 5C10 2.2 7.8 0 5 0S0 2.2 0 5S2.2 10 5 10C6.2 10 7.4 9.6 8.2 8.7L8.5
        9V9.6L12.3 13.5L13.5 12.3L9.6 8.5ZM5 8.5C3.1 8.5 1.5 6.9 1.5 5S3.1 1.5 5 1.5S8.5 3.1 8.5 5S6.9 8.5 5 8.5Z
    </Geometry>

    <!--  SEARCH DELETE ICON  -->
    <Geometry x:Key="Delete">
        M 0 0 M 2 3 L 3 2 L 8 7 L 13 2 L 14 3 L 9 8 L 14 13 L 13 14 L 8 9 L 3 14 L 2 13 L 7 8 Z M 16 0 M 0 16 M 16 16
    </Geometry>

    <!--  SEARCH CONTAINS ICON  -->
    <Geometry x:Key="StartsWith">
        M 0.6 1.3 V 0 C 1.1 -0.1 5.5 -1.7 6.2 1.6 V 7.2 H 5 V 6.2 C 4.5 6.7 4 7 3.5 7.2 H 1.4 C 0.4 6.8 0.1 6.1 0 5.2 C 0 4.7 0 3 3 2.8 H 4.9 V 1.7
        C 4.4 0.2 2.3 0.6 1 1.1 Z M 4.9 5.1 V 3.8 H 2.6 V 3.8 C 1 3.9 0.9 6.2 2.6 6.2 C 3.5 6.2 4 5.9 4.7 5.3 Z M 9.3 0.9 L 9.5 3.5 L 7.4 2 L 6.9 2.9
        L 9.2 4 L 6.9 5.1 L 7.3 6.1 L 9.5 4.7 L 9.3 7.2 H 10.4 L 10.2 4.6 L 12.3 6 L 12.8 5.1 L 10.5 4.1 L 12.8 2.9 L 12.3 2 L 10.2 3.5 L 10.4 0.9 Z
        M 16.5 0.9 H 17.6 L 17.4 3.4 L 19.5 2 L 20 2.9 L 17.7 4 L 20 5.2 L 19.5 6 L 17.4 4.7 L 17.6 7.2 H 16.5 L 16.6 4.7 L 14.5 6 L 14 5.2 L 16.3 4
        L 14 2.9 L 14.6 2 L 16.7 3.4 Z
    </Geometry>

    <!--  SEARCH STARTSWITH ICON  -->
    <Geometry x:Key="Contains">
        M 7.2 1.3 V 0 C 7.7 -0.1 12.1 -1.7 12.8 1.6 V 7.2 H 11.6 V 6.2 C 11.1 6.7 10.6 7 10.1 7.2 H 8 C 7 6.8 6.7 6.1 6.6 5.2 C 6.6 4.7 6.6 3 9.6 2.8
        H 11.5 V 1.7 C 11 0.2 8.9 0.6 7.6 1.1 Z M 11.5 5.1 V 3.8 H 9.2 C 7.5 4.1 8.1 6.2 9.2 6.2 C 10.1 6.2 10.6 5.9 11.3 5.3 Z M 2.4 1 L 2.6 3.5
        L 0.5 2.1 L 0 3 L 2.2 4.1 L 0 5.3 L 0.4 6.1 L 2.6 4.7 L 2.4 7.2 H 3.5 L 3.3 4.7 L 5.4 6.1 L 5.9 5.2 L 3.6 4.1 L 5.9 3 L 5.4 2.1 L 3.3 3.5
        L 3.5 1 Z M 16.5 0.9 H 17.6 L 17.4 3.5 L 19.5 2 L 20 3 L 17.7 4 L 20 5.2 L 19.5 6 L 17.4 4.7 L 17.6 7.2 H 16.5 L 16.6 4.7 L 14.5 6 L 14 5.2
        L 16.3 4.1 L 14 2.9 L 14.6 2 L 16.6 3.4 Z
    </Geometry>

    <!--  PLACEHOLDER SEARCH BOX  -->
    <Style x:Key="PlaceHolder"
           TargetType="{x:Type TextBox}">
        <Setter Property="Background"
                Value="Transparent" />
        <Setter Property="BorderBrush"
                Value="Transparent" />
        <Setter Property="BorderThickness"
                Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate x:Name="SearchControlTemplate"
                                 TargetType="{x:Type TextBox}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <!--  SEARCH TEXTBOX  -->
                        <TextBox x:Name="TextSource"
                                 Grid.Column="0"
                                 Margin="{TemplateBinding Margin}"
                                 Padding="{TemplateBinding Padding}"
                                 HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                 VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                 VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                 Panel.ZIndex="2"
                                 Background="Transparent"
                                 BorderBrush="Transparent"
                                 BorderThickness="0"
                                 Focusable="True"
                                 FontSize="{TemplateBinding FontSize}"
                                 FontWeight="{TemplateBinding FontWeight}"
                                 MaxLength="{TemplateBinding MaxLength}"
                                 Text="{Binding Path=Text, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}" />
                        <TextBox x:Name="TextBoxPlaceHolder"
                                 Grid.Column="0"
                                 Margin="{TemplateBinding Margin}"
                                 Padding="{TemplateBinding Padding}"
                                 HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                 VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                 VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                 Panel.ZIndex="1"
                                 Background="Transparent"
                                 BorderBrush="Transparent"
                                 BorderThickness="0"
                                 FontSize="{TemplateBinding FontSize}"
                                 FontWeight="{TemplateBinding FontWeight}"
                                 MaxLength="{TemplateBinding MaxLength}"
                                 Text="{TemplateBinding Tag}">
                            <TextBox.Style>
                                <Style TargetType="{x:Type TextBox}">
                                    <Setter Property="Foreground"
                                            Value="Transparent" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=Text, ElementName=TextSource}"
                                                     Value="">
                                            <Setter Property="Foreground"
                                                    Value="LightGray" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBox.Style>
                        </TextBox>

                        <!--  BUTTON CLEAR FILTER  -->
                        <Button x:Name="ClearSearchBoxBtn"
                                Grid.Column="1"
                                Margin="2"
                                Background="Transparent"
                                Command="{x:Static control:FilterDataGrid.ClearSearchBox}"
                                SnapsToDevicePixels="True"
                                UseLayoutRounding="True">
                            <Button.Style>
                                <Style TargetType="{x:Type Button}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="Button">
                                                <Border Background="Transparent"
                                                        SnapsToDevicePixels="True">
                                                    <!--  MAGNIFIER / DELETE ICON  -->
                                                    <Path x:Name="PathButton"
                                                          Width="18"
                                                          Height="18"
                                                          Margin="0"
                                                          Data="{StaticResource Delete}"
                                                          Fill="DarkSlateGray"
                                                          SnapsToDevicePixels="True"
                                                          Stretch="Uniform"
                                                          UseLayoutRounding="True" />
                                                </Border>
                                                <ControlTemplate.Triggers>
                                                    <DataTrigger Binding="{Binding ElementName=TextSource, Path=Text}"
                                                                 Value="">
                                                        <Setter Property="IsEnabled"
                                                                Value="False" />
                                                        <Setter TargetName="PathButton"
                                                                Property="Data"
                                                                Value="{StaticResource Magnifier}" />
                                                    </DataTrigger>
                                                    <Trigger Property="IsMouseOver"
                                                             Value="True">
                                                        <Setter Property="Cursor"
                                                                Value="Hand" />
                                                        <Setter TargetName="PathButton"
                                                                Property="Fill"
                                                                Value="Red" />
                                                        <Setter TargetName="PathButton"
                                                                Property="Stroke"
                                                                Value="Red" />
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </Button.Style>
                        </Button>

                        <!--  SEPARATOR  -->
                        <Border Grid.Column="2"
                                Width="1"
                                Margin="2,0,2,0"
                                Background="LightGray" />

                        <!--  TOGGLE BUTTON  -->
                        <ToggleButton Name="SearchToggleButton"
                                      Grid.Column="3"
                                      Margin="2,0,2,0"
                                      VerticalAlignment="Stretch"
                                      Background="Transparent"
                                      DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type control:FilterDataGrid}}}"
                                      IsChecked="{Binding StartsWith, UpdateSourceTrigger=PropertyChanged}"
                                      ToolTip="{Binding Translate.Toggle}">
                            <ToggleButton.Style>
                                <Style TargetType="{x:Type ToggleButton}">
                                    <Setter Property="Cursor"
                                            Value="Hand" />
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ToggleButton">
                                                <Border Padding="3"
                                                        Background="Transparent"
                                                        BorderBrush="LightGray"
                                                        BorderThickness="0">
                                                    <Path x:Name="PathToggle"
                                                          VerticalAlignment="Center"
                                                          Data="{StaticResource Contains}"
                                                          Fill="DarkSlateGray"
                                                          Stretch="UniformToFill" />
                                                </Border>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsChecked"
                                                             Value="True">
                                                        <Setter TargetName="PathToggle"
                                                                Property="Data"
                                                                Value="{StaticResource StartsWith}" />
                                                    </Trigger>
                                                    <Trigger Property="IsMouseOver"
                                                             Value="True">
                                                        <Setter TargetName="PathToggle"
                                                                Property="Fill"
                                                                Value="Black" />
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ToggleButton.Style>
                        </ToggleButton>
                    </Grid>
                    <!--  PLACEHOLDER TEXT  -->
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsFocused"
                                 Value="True">
                            <Setter TargetName="TextSource"
                                    Property="FocusManager.FocusedElement"
                                    Value="{Binding RelativeSource={RelativeSource Self}}" />
                        </Trigger>
                        <DataTrigger Binding="{Binding ElementName=SearchToggleButton, Path=IsChecked}"
                                     Value="True">
                            <Setter TargetName="TextBoxPlaceHolder"
                                    Property="Text"
                                    Value="{Binding Translate.StartsWith, Mode=OneWay}" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ElementName=SearchToggleButton, Path=IsChecked}"
                                     Value="False">
                            <Setter TargetName="TextBoxPlaceHolder"
                                    Property="Text"
                                    Value="{Binding Translate.Contains, Mode=OneWay}" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  DEFAULT STYLE AND CONTROLTEMPLATE FOR DATAGRID  -->
    <Style BasedOn="{StaticResource {x:Type DataGrid}}"
           TargetType="{x:Type control:FilterDataGrid}">

        <!--  DISABLING CanUserAddRows :  AggregateException when user can add row  -->
        <Setter Property="CanUserAddRows"
                Value="False" />

        <!--  ROWS COUNT TEMPLATE  -->
        <Setter Property="RowHeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}, Path=Header}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGrid}">
                    <Border Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="True">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <!--  CONTENT DATAGRID  -->
                            <ScrollViewer x:Name="DG_ScrollViewer"
                                          Grid.Row="0"
                                          CanContentScroll="True"
                                          Focusable="false">
                                <ScrollViewer.Template>
                                    <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                        <Grid ShowGridLines="False">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="*" />
                                                <RowDefinition Height="Auto" />
                                            </Grid.RowDefinitions>

                                            <Button Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
                                                    Command="{x:Static DataGrid.SelectAllCommand}"
                                                    Focusable="false"
                                                    Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle,
                                                                                              TypeInTargetAssembly={x:Type DataGrid}}}"
                                                    Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.All}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
                                            <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter"
                                                                            Grid.Row="0"
                                                                            Grid.Column="1"
                                                                            Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
                                            <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                                                    Grid.Row="1"
                                                                    Grid.Column="0"
                                                                    Grid.ColumnSpan="2"
                                                                    CanContentScroll="{TemplateBinding CanContentScroll}" />
                                            <ScrollBar x:Name="PART_VerticalScrollBar"
                                                       Grid.Row="1"
                                                       Grid.Column="2"
                                                       Maximum="{TemplateBinding ScrollableHeight}"
                                                       Orientation="Vertical"
                                                       ViewportSize="{TemplateBinding ViewportHeight}"
                                                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                                                       Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
                                            <Grid Grid.Row="2"
                                                  Grid.Column="1">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="{Binding NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>
                                                <ScrollBar x:Name="PART_HorizontalScrollBar"
                                                           Grid.Column="1"
                                                           Maximum="{TemplateBinding ScrollableWidth}"
                                                           Orientation="Horizontal"
                                                           ViewportSize="{TemplateBinding ViewportWidth}"
                                                           Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                                                           Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
                                            </Grid>
                                        </Grid>
                                    </ControlTemplate>
                                </ScrollViewer.Template>
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </ScrollViewer>

                            <!--  STATUS BAR & RESULT FILTER  -->
                            <Border x:Name="BorderStatusBar"
                                    Grid.Row="1"
                                    Padding="4,2"
                                    Background="Transparent"
                                    BorderBrush="LightGray"
                                    BorderThickness="0,1">
                                <Border.Style>
                                    <Style TargetType="Border">
                                        <Setter Property="Visibility"
                                                Value="Collapsed" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=ShowStatusBar, RelativeSource={RelativeSource AncestorType={x:Type control:FilterDataGrid}}}"
                                                         Value="True">
                                                <Setter Property="Visibility"
                                                        Value="Visible" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Border.Style>

                                <UniformGrid Columns="2"
                                             DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type control:FilterDataGrid}}}">

                                    <!--  RESULT STATUS  -->
                                    <TextBlock HorizontalAlignment="Left">
                                        <TextBlock.Text>
                                            <MultiBinding Converter="{StaticResource StringFormatConverter}">
                                                <Binding Path="Translate.Status" />
                                                <Binding Path="Items.Count"
                                                         UpdateSourceTrigger="PropertyChanged" />
                                                <Binding Path="ItemsSourceCount" />
                                            </MultiBinding>
                                        </TextBlock.Text>
                                    </TextBlock>

                                    <!--  ELAPSED TIME  -->
                                    <TextBlock HorizontalAlignment="Right">
                                        <TextBlock.Text>
                                            <MultiBinding Converter="{StaticResource StringFormatConverter}">
                                                <Binding Path="Translate.ElapsedTime"
                                                         UpdateSourceTrigger="PropertyChanged" />
                                                <Binding Path="ElapsedTime" />
                                            </MultiBinding>
                                        </TextBlock.Text>
                                        <TextBlock.Style>
                                            <Style TargetType="TextBlock">
                                                <Setter Property="Visibility"
                                                        Value="Collapsed" />
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding ShowElapsedTime}"
                                                                 Value="True">
                                                        <Setter Property="Visibility"
                                                                Value="Visible" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </TextBlock.Style>
                                    </TextBlock>
                                </UniformGrid>
                            </Border>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  DATAGRIDCOLUMNHEADER STYLE  -->
    <Style BasedOn="{StaticResource {x:Type DataGridColumnHeader}}"
           TargetType="DataGridColumnHeader">
        <Setter Property="HorizontalContentAlignment"
                Value="Stretch" />
    </Style>

    <!--  DATATEMPLATE OF DATAGRIDCOLUMNHEADER  -->
    <DataTemplate x:Key="DataGridHeaderTemplate">

        <!--  HEADER STRECH TO CONTENTPRESENTER OF DATAGRIDCOLUMNHEADER  -->
        <Grid x:Name="ContainerFilterGrid"
              Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContentPresenter}, Mode=FindAncestor, AncestorLevel=1}, Path=ActualWidth}"
              HorizontalAlignment="Stretch"
              Background="Transparent">

            <!--  HEADER/BUTTON  -->
            <Grid x:Name="GridHeaderButton"
                  ShowGridLines="False">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <!--  RENDER THE HEADER TEXT  -->
                <TextBlock Grid.Column="0"
                           Text="{Binding}" />

                <!--  FILTER BUTTON  -->
                <Button Name="filterButton"
                        Grid.Column="1"
                        Width="19"
                        Height="19"
                        Background="Transparent"
                        BorderBrush="DarkGray"
                        BorderThickness="1"
                        Command="{x:Static control:FilterDataGrid.ShowFilter}"
                        Cursor="Hand"
                        Opacity="0.5"
                        OverridesDefaultStyle="True"
                        SnapsToDevicePixels="True"
                        UseLayoutRounding="True">
                    <Button.Style>
                        <Style TargetType="{x:Type Button}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type Button}">
                                        <Border Padding="2"
                                                Background="{TemplateBinding Background}"
                                                BorderBrush="{TemplateBinding BorderBrush}"
                                                BorderThickness="1"
                                                SnapsToDevicePixels="True"
                                                UseLayoutRounding="True">
                                            <Path x:Name="PathFilterIcon"
                                                  Margin="0"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  Data="{StaticResource Filter}"
                                                  Fill="DarkSlateGray"
                                                  Stretch="Uniform" />
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </Button.Style>
                </Button>
            </Grid>

            <!--  POPUP  -->
            <Popup Name="FilterPopup"
                   AllowsTransparency="True"
                   IsOpen="False"
                   PlacementTarget="{Binding ElementName=ContainerFilterGrid}"
                   StaysOpen="{StaticResource StayOpen}">

                <Border x:Name="PopUpBorder"
                        Padding="0"
                        Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
                        BorderBrush="LightGray"
                        BorderThickness="1">

                    <Grid x:Name="SizableContentGrid"
                          MinWidth="{StaticResource PopupWidth}"
                          MinHeight="{StaticResource PopupHeight}"
                          ShowGridLines="False"
                          ZIndex="1">

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"
                                              MinWidth="32" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <!--  BUTTON CLEAR FILTER  -->
                        <Button x:Name="ClearFilterBnt"
                                Grid.Row="2"
                                Grid.Column="0"
                                Grid.ColumnSpan="2"
                                Margin="2,10,2,2"
                                Padding="4"
                                HorizontalAlignment="Stretch"
                                Command="{x:Static control:FilterDataGrid.RemoveFilter}"
                                Content="{Binding Path=Content, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridColumnHeader}}, UpdateSourceTrigger=PropertyChanged}"
                                FontSize="13"
                                OverridesDefaultStyle="True">
                            <Button.Style>
                                <Style TargetType="{x:Type Button}">
                                    <Setter Property="Foreground"
                                            Value="DarkSlateGray" />
                                    <Setter Property="SnapsToDevicePixels"
                                            Value="True" />
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type Button}">
                                                <Border x:Name="BorderContent"
                                                        Padding="{TemplateBinding Padding}"
                                                        BorderBrush="Transparent"
                                                        BorderThickness="0"
                                                        SnapsToDevicePixels="True"
                                                        UseLayoutRounding="True">
                                                    <Grid x:Name="ContentGrid"
                                                          Background="Transparent">
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="Auto" />
                                                            <ColumnDefinition Width="*" />
                                                        </Grid.ColumnDefinitions>
                                                        <Path Grid.Column="0"
                                                              Width="16"
                                                              Margin="0,0,10,0"
                                                              Data="{StaticResource FilterDelete}"
                                                              Fill="{TemplateBinding Foreground}"
                                                              Stretch="Uniform" />

                                                        <TextBlock x:Name="ContentPresenter"
                                                                   Grid.Column="1"
                                                                   HorizontalAlignment="Stretch"
                                                                   DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type control:FilterDataGrid}}}">
                                                            <TextBlock.Text>
                                                                <MultiBinding Converter="{StaticResource StringFormatConverter}">
                                                                    <MultiBinding.Bindings>
                                                                        <Binding Path="Translate.Clear"
                                                                                 TargetNullValue=""
                                                                                 UpdateSourceTrigger="PropertyChanged" />
                                                                        <Binding ElementName="ClearFilterBnt"
                                                                                 Path="Content" />
                                                                    </MultiBinding.Bindings>
                                                                </MultiBinding>
                                                            </TextBlock.Text>
                                                        </TextBlock>
                                                    </Grid>
                                                </Border>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsMouseOver"
                                                             Value="True">
                                                        <Setter TargetName="BorderContent"
                                                                Property="Background"
                                                                Value="#F0F0F0" />
                                                    </Trigger>
                                                    <Trigger Property="IsPressed"
                                                             Value="True">
                                                        <Setter TargetName="BorderContent"
                                                                Property="Background">
                                                            <Setter.Value>
                                                                <SolidColorBrush Opacity="0.8"
                                                                                 Color="LightGray" />
                                                            </Setter.Value>
                                                        </Setter>
                                                    </Trigger>
                                                    <Trigger Property="IsEnabled"
                                                             Value="False">
                                                        <Setter Property="Foreground">
                                                            <Setter.Value>
                                                                <SolidColorBrush Opacity="0.5"
                                                                                 Color="DarkSlateGray" />
                                                            </Setter.Value>
                                                        </Setter>
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </Button.Style>
                        </Button>

                        <!--  SEPARATOR  -->
                        <Separator Grid.Row="3"
                                   Grid.Column="1"
                                   Margin="0,2"
                                   Background="LightGray" />

                        <!--  SEARCH BOX  -->
                        <Border Grid.Row="4"
                                Grid.Column="1"
                                Margin="0,4,4,2"
                                Padding="0,2"
                                VerticalAlignment="Top"
                                Background="Transparent"
                                BorderBrush="LightGray"
                                BorderThickness="1">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <TextBox x:Name="SearchBox"
                                         Grid.Column="0"
                                         Margin="0"
                                         Padding="2,0,0,0"
                                         HorizontalAlignment="Stretch"
                                         VerticalContentAlignment="Center"
                                         AcceptsReturn="False"
                                         DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type control:FilterDataGrid}}}"
                                         Focusable="True"
                                         FontSize="13"
                                         MaxLength="20"
                                         Style="{StaticResource PlaceHolder}"
                                         Tag="{Binding Translate.Contains}">
                                    <TextBox.InputBindings>
                                        <KeyBinding Key="Enter"
                                                    Command="{x:Static control:FilterDataGrid.ApplyFilter}" />
                                    </TextBox.InputBindings>
                                </TextBox>
                            </Grid>
                        </Border>

                        <!--  ICON (current filter is set)  -->
                        <Path x:Name="PathIsFiltered"
                              Grid.Row="5"
                              Grid.Column="0"
                              Width="19"
                              Height="20"
                              Margin="0,5,0,0"
                              VerticalAlignment="Top"
                              Data="{StaticResource FilterChecked}"
                              Fill="DarkSlateGray"
                              Stretch="Fill"
                              Stroke="DarkSlateGray"
                              StrokeThickness="0.2">
                            <Path.Style>
                                <Style TargetType="Path">
                                    <Setter Property="Visibility"
                                            Value="Hidden" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ElementName=ClearFilterBnt, Path=IsEnabled}"
                                                     Value="True">
                                            <Setter Property="Visibility"
                                                    Value="Visible" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Path.Style>
                        </Path>

                        <!--  LISTBOX / TREEVIEW  -->
                        <Border Grid.Row="5"
                                Grid.Column="1"
                                Margin="0,4,4,4"
                                BorderThickness="0">

                            <Grid x:Name="GridItemControl">

                                <ListBox x:Name="PopupListBox"
                                         Grid.Row="0"
                                         Padding="2"
                                         HorizontalAlignment="Stretch"
                                         VerticalAlignment="Stretch"
                                         BorderBrush="LightGray"
                                         BorderThickness="1"
                                         ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                         ScrollViewer.VerticalScrollBarVisibility="Auto"
                                         Visibility="Collapsed">
                                    <ListBox.ItemContainerStyle>
                                        <Style BasedOn="{StaticResource {x:Type ListBoxItem}}"
                                               TargetType="{x:Type ListBoxItem}">
                                            <Setter Property="HorizontalContentAlignment"
                                                    Value="Left" />
                                            <Setter Property="VerticalContentAlignment"
                                                    Value="Center" />
                                        </Style>
                                    </ListBox.ItemContainerStyle>
                                    <ListBox.ItemTemplate>
                                        <!--
                                            ContentStringFormat="{}{0}"
                                            Content="{Binding Label, ConverterCulture=en-US}"
                                            ContentStringFormat="F2, en-US"
                                            the value of the label is a string, so it cannot be formatted
                                        -->
                                        <DataTemplate DataType="{x:Type control:FilterItem}">
                                            <CheckBox x:Name="CheckBox"
                                                      Width="Auto"
                                                      HorizontalAlignment="Stretch"
                                                      HorizontalContentAlignment="Stretch"
                                                      Command="{x:Static control:FilterDataGrid.IsChecked}"
                                                      CommandParameter="{Binding}"
                                                      Content="{Binding Label}"
                                                      FontWeight="Normal"
                                                      IsChecked="{Binding IsChecked}"
                                                      IsThreeState="False" />
                                            <DataTemplate.Triggers>
                                                <DataTrigger Binding="{Binding Level}"
                                                             Value="1">
                                                    <Setter TargetName="CheckBox"
                                                            Property="Margin"
                                                            Value="4,0,0,0" />
                                                </DataTrigger>
                                            </DataTemplate.Triggers>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>

                                <TreeView x:Name="PopupTreeview"
                                          Grid.Row="0"
                                          BorderBrush="LightGray"
                                          BorderThickness="1"
                                          ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                          ScrollViewer.VerticalScrollBarVisibility="Auto"
                                          Visibility="Collapsed">
                                    <TreeView.ItemTemplate>
                                        <HierarchicalDataTemplate DataType="control:FilterItem"
                                                                  ItemsSource="{Binding Children}">
                                            <StackPanel Orientation="Horizontal">
                                                <CheckBox x:Name="CheckBoxTree"
                                                          VerticalAlignment="Center"
                                                          Focusable="False"
                                                          IsChecked="{Binding IsChecked, UpdateSourceTrigger=PropertyChanged}" />
                                                <ContentPresenter Margin="2"
                                                                  Content="{Binding Label}" />
                                            </StackPanel>
                                            <DataTemplate.Triggers>
                                                <DataTrigger Binding="{Binding Level}"
                                                             Value="1">
                                                    <Setter TargetName="CheckBoxTree"
                                                            Property="Margin"
                                                            Value="4,0,0,0" />
                                                </DataTrigger>
                                            </DataTemplate.Triggers>
                                        </HierarchicalDataTemplate>
                                    </TreeView.ItemTemplate>
                                    <TreeView.ItemContainerStyle>
                                        <Style BasedOn="{StaticResource {x:Type TreeViewItem}}"
                                               TargetType="{x:Type TreeViewItem}">
                                            <Setter Property="OverridesDefaultStyle"
                                                    Value="True" />
                                            <Setter Property="IsExpanded"
                                                    Value="False" />
                                            <Setter Property="HorizontalContentAlignment"
                                                    Value="Stretch" />
                                            <Setter Property="VerticalContentAlignment"
                                                    Value="Stretch" />
                                            <Setter Property="Visibility"
                                                    Value="Visible" />
                                        </Style>
                                    </TreeView.ItemContainerStyle>
                                </TreeView>
                            </Grid>
                        </Border>

                        <!--  OK/CANCEL BUTTON  -->
                        <UniformGrid Grid.Row="6"
                                     Grid.Column="1"
                                     Margin="0,6,4,6"
                                     HorizontalAlignment="Right"
                                     Background="Transparent"
                                     Columns="2"
                                     DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type control:FilterDataGrid}}}">

                            <Button Width="100"
                                    Margin="0"
                                    HorizontalAlignment="Left"
                                    Command="{x:Static control:FilterDataGrid.ApplyFilter}"
                                    Content="{Binding Translate.Ok}" />

                            <Button Width="100"
                                    Margin="6,0,0,0"
                                    HorizontalAlignment="Right"
                                    Command="{x:Static control:FilterDataGrid.CancelFilter}"
                                    Content="{Binding Translate.Cancel}" />
                        </UniformGrid>

                        <!--  RESIZE GRIP  -->
                        <Thumb x:Name="PopupThumb"
                               Grid.Row="7"
                               Grid.Column="0"
                               Grid.ColumnSpan="2"
                               Width="20"
                               Height="Auto"
                               Margin="0,0,2,2"
                               HorizontalAlignment="Right"
                               VerticalAlignment="Bottom"
                               SnapsToDevicePixels="True"
                               UseLayoutRounding="True">
                            <Thumb.Style>
                                <Style TargetType="{x:Type Thumb}">
                                    <Style.Setters>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate>
                                                    <Grid x:Name="resizeVisual"
                                                          HorizontalAlignment="Right"
                                                          VerticalAlignment="Bottom"
                                                          Background="Transparent"
                                                          DockPanel.Dock="Right"
                                                          SnapsToDevicePixels="True"
                                                          UseLayoutRounding="True">
                                                        <Path Width="12"
                                                              Height="12"
                                                              Margin="0"
                                                              Data="{StaticResource GripSizeIcon}"
                                                              Stretch="None"
                                                              Stroke="LightSlateGray"
                                                              StrokeThickness="1" />
                                                        <Grid.Style>
                                                            <Style TargetType="{x:Type Grid}">
                                                                <Style.Triggers>
                                                                    <Trigger Property="IsMouseOver"
                                                                             Value="True">
                                                                        <Setter Property="Cursor"
                                                                                Value="SizeNWSE" />
                                                                    </Trigger>
                                                                </Style.Triggers>
                                                            </Style>
                                                        </Grid.Style>
                                                    </Grid>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style.Setters>
                                </Style>
                            </Thumb.Style>
                        </Thumb>
                    </Grid>
                </Border>
            </Popup>
        </Grid>
    </DataTemplate>
</ResourceDictionary>
