<ResourceDictionary
    x:Class="ExtendedGrid.Styles.DataGridGeneric"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Base="clr-namespace:ExtendedGrid.Base"
    xmlns:Classes="clr-namespace:ExtendedGrid.Classes"
    xmlns:Converter="clr-namespace:ExtendedGrid.Converter"
    xmlns:ExtendedGridControl="clr-namespace:ExtendedGrid.ExtendedGridControl"
    xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
    xmlns:UserControls="clr-namespace:ExtendedGrid.UserControls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Brushes.xaml" />
    </ResourceDictionary.MergedDictionaries>
    <Style x:Key="{x:Type DataGridRow}" TargetType="{x:Type DataGridRow}">
        <!--<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />-->
        <Setter Property="SnapsToDevicePixels" Value="true" />
        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
        <Setter Property="ValidationErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <TextBlock
                        Margin="2,0,0,0"
                        VerticalAlignment="Center"
                        Foreground="Red"
                        Text="!" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRow}">
                    <Border
                        x:Name="DGR_Border"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        SnapsToDevicePixels="True">
                        <SelectiveScrollingGrid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <DataGridCellsPresenter
                                Grid.Column="1"
                                ItemsPanel="{TemplateBinding ItemsPanel}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

                            <DataGridDetailsPresenter
                                Grid.Row="1"
                                Grid.Column="1"
                                SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding RelativeSource={RelativeSource AncestorType={x:Type ExtendedGridControl:ExtendedDataGrid}}, Path=AreRowDetailsFrozen, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}}"
                                Visibility="{TemplateBinding DetailsVisibility}" />

                            <DataGridRowHeader
                                Grid.RowSpan="2"
                                SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
                                Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type ExtendedGridControl:ExtendedDataGrid}}, Path=HeadersVisibility, Converter={x:Static DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static DataGridHeadersVisibility.Row}}" />
                        </SelectiveScrollingGrid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}">
                    <ControlTemplate.Resources>
                        <Style x:Key="ToggleButtonStyle" TargetType="ToggleButton">
                            <Setter Property="Background" Value="Transparent" />
                            <Setter Property="IsEnabled" Value="True" />
                            <Setter Property="IsTabStop" Value="False" />
                            <Setter Property="Cursor" Value="Hand" />
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ToggleButton">
                                        <Grid
                                            x:Name="Button"
                                            Width="16"
                                            Height="16"
                                            Margin="0,4,0,0"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Top">
                                            <Rectangle
                                                Width="Auto"
                                                Height="Auto"
                                                HorizontalAlignment="Stretch"
                                                VerticalAlignment="Stretch"
                                                Fill="Transparent"
                                                RadiusX="3"
                                                RadiusY="3"
                                                Stroke="{DynamicResource DynamicDefaultControlForegroundBrush}" />
                                            <Rectangle
                                                x:Name="CollapsedVisual"
                                                Width="2"
                                                Height="8"
                                                Margin="7,4,0,0"
                                                HorizontalAlignment="Left"
                                                VerticalAlignment="Top"
                                                Fill="{DynamicResource DynamicDefaultControlForegroundBrush}"
                                                RadiusX="0"
                                                RadiusY="0"
                                                Visibility="Collapsed" />
                                            <Rectangle
                                                Width="8"
                                                Height="2"
                                                Margin="4,7,0,0"
                                                HorizontalAlignment="Left"
                                                VerticalAlignment="Top"
                                                Fill="{DynamicResource DynamicDefaultControlForegroundBrush}"
                                                RadiusX="0"
                                                RadiusY="0" />
                                        </Grid>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsChecked" Value="False">
                                                <Setter TargetName="CollapsedVisual" Property="Visibility" Value="Visible" />
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>

                                </Setter.Value>
                            </Setter>
                        </Style>
                        <Style x:Key="{x:Type Expander}" TargetType="{x:Type Expander}">
                            <Setter Property="Foreground" Value="{DynamicResource DynamicDefaultControlForegroundBrush}" />
                            <Setter Property="Background" Value="Transparent" />
                            <Setter Property="Padding" Value="1" />
                            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                            <Setter Property="VerticalContentAlignment" Value="Stretch" />
                            <Setter Property="BorderBrush" Value="{DynamicResource DynamicSeperatorBrush}" />
                            <Setter Property="BorderThickness" Value="1" />
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type Expander}">
                                        <Border
                                            Background="{TemplateBinding Background}"
                                            BorderBrush="{DynamicResource DynamicSeperatorBrush}"
                                            BorderThickness="{TemplateBinding BorderThickness}"
                                            CornerRadius="3"
                                            SnapsToDevicePixels="true">
                                            <DockPanel>

                                                <Border
                                                    BorderBrush="{DynamicResource DynamicSeperatorBrush}"
                                                    BorderThickness="{TemplateBinding BorderThickness}"
                                                    DockPanel.Dock="Top">
                                                    <StackPanel Orientation="Horizontal">
                                                        <ToggleButton
                                                            x:Name="HeaderSite"
                                                            MinWidth="0"
                                                            MinHeight="0"
                                                            Margin="1"
                                                            Padding="{TemplateBinding Padding}"
                                                            HorizontalAlignment="Left"
                                                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                                            Content="{TemplateBinding Header}"
                                                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                                                            ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                                            FocusVisualStyle="{DynamicResource ExpanderHeaderFocusVisual}"
                                                            FontFamily="{TemplateBinding FontFamily}"
                                                            FontSize="{TemplateBinding FontSize}"
                                                            FontStretch="{TemplateBinding FontStretch}"
                                                            FontStyle="{TemplateBinding FontStyle}"
                                                            FontWeight="{TemplateBinding FontWeight}"
                                                            Foreground="{TemplateBinding Foreground}"
                                                            IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                                            Style="{StaticResource ToggleButtonStyle}" />
                                                        <TextBlock
                                                            VerticalAlignment="Center"
                                                            FontWeight="Bold"
                                                            Text="{Binding RelativeSource={RelativeSource AncestorType=Expander}, Path=Header}" />
                                                    </StackPanel>

                                                </Border>

                                                <ContentPresenter
                                                    x:Name="ExpandSite"
                                                    Margin="{TemplateBinding Padding}"
                                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                    DockPanel.Dock="Bottom"
                                                    Focusable="false"
                                                    Visibility="Collapsed" />
                                            </DockPanel>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsExpanded" Value="true">
                                                <Setter TargetName="ExpandSite" Property="Visibility" Value="Visible" />
                                            </Trigger>
                                            <Trigger Property="IsEnabled" Value="false">
                                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ControlTemplate.Resources>
                    <Expander
                        Margin="4,0,0,3"
                        Background="{DynamicResource DynamicHeaderBackgroundBrush}"
                        BorderBrush="{DynamicResource DynamicHeaderPressedBackgroundBrush}"
                        BorderThickness="1,0.5,1,0.5"
                        Collapsed="ExpanderExpanded"
                        Expanded="ExpanderExpanded"
                        Header="{Binding Name}"
                        IsExpanded="True">

                        <ItemsPresenter />
                    </Expander>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <GroupStyle x:Key="CustomGroupStyle" ContainerStyle="{StaticResource GroupHeaderStyle}">
        <GroupStyle.Panel>
            <ItemsPanelTemplate>
                <!--<Primitives:DataGridRowsPresenter Margin="4,0,0,0" />-->
                <Classes:CustomDataGridRowsPresenter />
            </ItemsPanelTemplate>
        </GroupStyle.Panel>
    </GroupStyle>
    <Converter:RowSummariesValueConverter x:Key="RowSummariesValueConverter" />
    <Converter:RowSummaryVisibiltyConverter x:Key="RowSummaryVisibiltyConverter" />
    <Converter:RowSummariesClearButtonIsEnabledConverter x:Key="RowSummariesClearButtonIsEnabledConverter" />
    <Converter:GroupByButtonVisibilityConverter x:Key="GroupByButtonVisibilityConverter" />

    <!--  Value converters  -->
    <BooleanToVisibilityConverter x:Key="bool2VisibilityConverter" />
    <ContextMenu
        x:Key="DataGridHeaderColumnChooser"
        Width="Auto"
        HorizontalAlignment="Stretch"
        HorizontalContentAlignment="Stretch"
        StaysOpen="True">
        <MenuItem
            HorizontalAlignment="Stretch"
            HorizontalContentAlignment="Stretch"
            StaysOpenOnClick="True">
            <MenuItem.Header>
                <UserControls:ColumnChooserControl />
            </MenuItem.Header>
        </MenuItem>
    </ContextMenu>

    <ContentControl x:Key="SortContenetControl">


        <StackPanel VerticalAlignment="Center" DockPanel.Dock="Right">
            <Path
                Width="8"
                Height="6"
                Data="M0,0 L1,0 0.5,1 z"
                Fill="{DynamicResource DynamicSortBrush}"
                RenderTransformOrigin="0.5,0.4"
                Stretch="Fill"
                Tag="{x:Null}"
                Visibility="Visible" />

        </StackPanel>

    </ContentControl>
    <Style x:Key="ColumnHeaderRightGripperStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="8" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Cursor" Value="SizeWE" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!--  DataGridColumnHeader Left Gripper Style  -->
    <Style
        x:Key="ColumnHeaderLeftGripperStyle"
        BasedOn="{StaticResource ColumnHeaderRightGripperStyle}"
        TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="8" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Cursor" Value="SizeWE" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border
                        Name="Border"
                        Padding="{TemplateBinding Padding}"
                        Background="{TemplateBinding Background}">
                        <Canvas>
                            <Line
                                RenderOptions.EdgeMode="Aliased"
                                Stroke="{DynamicResource DynamicHeaderBorderBrush}"
                                X1="7"
                                X2="7"
                                Y1="{Binding ElementName=Border, Path=ActualHeight}"
                                Y2="0" />
                        </Canvas>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!--  DataGridColumnHeader Style  -->
    <Style x:Key="RowSummariesHeader" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Foreground" Value="{DynamicResource DynamicDefaultControlForegroundBrush}" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Background" Value="{DynamicResource DynamicHeaderBackgroundBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource DynamicHeaderBorderBrush}" />
        <Setter Property="BorderThickness" Value="0,1,0,1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                    <Grid>
                        <Themes:DataGridHeaderBorder
                            x:Name="headerBorder"
                            Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            IsClickable="{TemplateBinding CanUserSort}"
                            IsHovered="{TemplateBinding IsMouseOver}"
                            IsPressed="{TemplateBinding IsPressed}"
                            SeparatorBrush="{TemplateBinding SeparatorBrush}"
                            SeparatorVisibility="Visible">
                            <Border BorderBrush="{DynamicResource DynamicHeaderBorderBrush}" BorderThickness="1,0,0,0">
                                <ContentControl Margin="4,0,4,0">
                                    <StackPanel>
                                        <StackPanel x:Name="sumPanel" Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Sum=</TextBlock>
                                            <TextBlock x:Name="sumTextBlock">
                                                <TextBlock.Text>
                                                    <MultiBinding Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Sum">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridColumnHeader}" />
                                                        <Binding Path="RowSummariesTable" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" />
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Average=</TextBlock>
                                            <TextBlock>
                                                <TextBlock.Text>
                                                    <MultiBinding Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Average">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridColumnHeader}" />
                                                        <Binding Path="RowSummariesTable" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" />
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Count=</TextBlock>
                                            <TextBlock>
                                                <TextBlock.Text>
                                                    <MultiBinding Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Count">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridColumnHeader}" />
                                                        <Binding Path="RowSummariesTable" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" />
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Min=</TextBlock>
                                            <TextBlock>
                                                <TextBlock.Text>
                                                    <MultiBinding Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Min">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridColumnHeader}" />
                                                        <Binding Path="RowSummariesTable" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" />
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Max=</TextBlock>
                                            <TextBlock>
                                                <TextBlock.Text>
                                                    <MultiBinding Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Max">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridColumnHeader}" />
                                                        <Binding Path="RowSummariesTable" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" />
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Smallest=</TextBlock>
                                            <TextBlock>
                                                <TextBlock.Text>
                                                    <MultiBinding Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Smallest">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridColumnHeader}" />
                                                        <Binding Path="RowSummariesTable" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" />
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Largest=</TextBlock>
                                            <TextBlock>
                                                <TextBlock.Text>
                                                    <MultiBinding Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Largest">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridColumnHeader}" />
                                                        <Binding Path="RowSummariesTable" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" />
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                    </StackPanel>
                                </ContentControl>
                            </Border>
                        </Themes:DataGridHeaderBorder>
                        <Thumb
                            x:Name="PART_LeftHeaderGripper"
                            HorizontalAlignment="Left"
                            Style="{StaticResource ColumnHeaderRightGripperStyle}" />
                        <Thumb
                            x:Name="PART_RightHeaderGripper"
                            HorizontalAlignment="Right"
                            Style="{StaticResource ColumnHeaderLeftGripperStyle}" />

                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" Value="{DynamicResource DynamicHeaderHighlightedBackgoundBrush}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" Value="{DynamicResource DynamicHeaderPressedBackgroundBrush}" />
                        </Trigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>




    <!--  DataGridColumnHeader Style  -->
    <Style x:Key="ColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Background" Value="{DynamicResource DynamicHeaderBackgroundBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource DynamicHeaderBorderBrush}" />
        <EventSetter Event="SizeChanged" Handler="ColumnSizeChanged" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Background" Value="{DynamicResource DynamicHeaderBackgroundBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource DynamicHeaderBorderBrush}" />
        <Setter Property="BorderThickness" Value="0,1,0,1" />
        <Setter Property="ContextMenu" Value="{StaticResource DataGridHeaderColumnChooser}" />
        <Setter Property="Height" Value="30" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                    <Grid>
                        <!--  MouseDown="HeaderClickMouseDown" TODO  -->
                        <Themes:DataGridHeaderBorder
                            x:Name="headerBorder"
                            Padding="{TemplateBinding Padding}"
                            HorizontalAlignment="Stretch"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            IsClickable="{TemplateBinding CanUserSort}"
                            IsHovered="{TemplateBinding IsMouseOver}"
                            IsPressed="{TemplateBinding IsPressed}"
                            SeparatorBrush="{TemplateBinding SeparatorBrush}"
                            SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
                            SortDirection="{TemplateBinding SortDirection}">
                            <Border BorderBrush="{StaticResource HeaderInnerBorderBrush}" BorderThickness="0,1,0,0">
                                <Border.Resources>
                                    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
                                </Border.Resources>
                                <DockPanel LastChildFill="True">
                                    <Popup
                                        x:Name="popupDrag"
                                        MinWidth="150"
                                        MaxWidth="200"
                                        AllowsTransparency="False"
                                        IsHitTestVisible="True"
                                        IsOpen="False"
                                        Placement="RelativePoint"
                                        StaysOpen="True"
                                        Tag="False">
                                        <StackPanel Focusable="True" LostFocus="PopLostFocus">
                                            <Button
                                                x:Name="btnClear"
                                                MinHeight="24"
                                                Click="ClearClicked"
                                                FontFamily="{TemplateBinding FontFamily}"
                                                FontSize="9"
                                                IsEnabled="False"
                                                LostFocus="PopLostFocus">
                                                (Clear Filter)
                                            </Button>
                                            <Grid Visibility="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=SearchAutoFilterVisibility}">
                                                <TextBlock
                                                    Margin="3,0,0,0"
                                                    Background="White"
                                                    Foreground="DarkGray"
                                                    Text="Search..."
                                                    Visibility="{Binding ElementName=txtSearchAutoFilter, Path=Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                                <Border BorderBrush="DarkGray" BorderThickness="1">
                                                    <DockPanel LastChildFill="True">
                                                        <Image
                                                            Width="20"
                                                            Height="20"
                                                            Panel.ZIndex="100"
                                                            DockPanel.Dock="Right"
                                                            RenderOptions.BitmapScalingMode="HighQuality"
                                                            Source="../Images/search.jpg" />
                                                        <TextBox
                                                            x:Name="txtSearchAutoFilter"
                                                            Height="22"
                                                            HorizontalAlignment="Stretch"
                                                            Tag="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}}"
                                                            TextChanged="AutoFilterSearchTextChanged">
                                                            <TextBox.Resources>
                                                                <Style TargetType="TextBox">
                                                                    <Style.Triggers>
                                                                        <Trigger Property="Text" Value="{x:Null}">
                                                                            <Setter Property="Background" Value="Transparent" />
                                                                        </Trigger>
                                                                        <Trigger Property="Text" Value="">
                                                                            <Setter Property="Background" Value="Transparent" />
                                                                        </Trigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </TextBox.Resources>
                                                        </TextBox>
                                                    </DockPanel>
                                                </Border>
                                            </Grid>
                                            <ListBox
                                                x:Name="autoFilterList"
                                                MaxHeight="350"
                                                FontFamily="{TemplateBinding FontFamily}"
                                                LostFocus="PopLostFocus"
                                                ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                                ScrollViewer.VerticalScrollBarVisibility="Auto"
                                                VirtualizingStackPanel.IsVirtualizing="True">
                                                <ListBox.Resources>
                                                    <Style TargetType="{x:Type ListBoxItem}">
                                                        <Style.Triggers>
                                                            <DataTrigger Binding="{Binding Hide}" Value="True">
                                                                <Setter Property="Visibility" Value="Collapsed" />
                                                            </DataTrigger>
                                                        </Style.Triggers>

                                                    </Style>
                                                </ListBox.Resources>
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <CheckBox
                                                            x:Name="chkBox"
                                                            Margin="0"
                                                            Checked="Checked"
                                                            Content="{Binding Name}"
                                                            FontSize="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=AutoFilterFontSize}"
                                                            Foreground="{DynamicResource DynamicAutoFilterForegroundBrushBrush}"
                                                            IsChecked="{Binding IsChecked}"
                                                            Tag="{Binding IsSelectAll}"
                                                            Unchecked="UnChecked" />
                                                        <DataTemplate.Triggers>
                                                            <Trigger SourceName="chkBox" Property="Tag" Value="(Select All)">
                                                                <Setter TargetName="chkBox" Property="FontWeight" Value="Bold" />
                                                            </Trigger>
                                                        </DataTemplate.Triggers>
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </StackPanel>
                                    </Popup>
                                    <Popup
                                        x:Name="sigmaDrag"
                                        MinWidth="150"
                                        MaxWidth="200"
                                        AllowsTransparency="False"
                                        IsHitTestVisible="True"
                                        IsOpen="False"
                                        Placement="RelativePoint"
                                        StaysOpen="True"
                                        Tag="False">
                                        <StackPanel Focusable="True" LostFocus="PopLostFocus">
                                            <Button
                                                x:Name="btnSigmaClear"
                                                MinHeight="24"
                                                Click="ClearSummaries"
                                                FontFamily="{TemplateBinding FontFamily}"
                                                FontSize="9"
                                                LostFocus="PopSigmaLostFocus">
                                                (Clear Summaries
                                                <Button.Tag>
                                                    <MultiBinding Converter="{StaticResource RowSummariesClearButtonIsEnabledConverter}" ConverterParameter="Sum">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridColumnHeader}" />
                                                        <Binding Path="RowSummariesTable" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" />
                                                    </MultiBinding>
                                                </Button.Tag>
                                            </Button>
                                            <ListBox
                                                x:Name="sigmaList"
                                                MaxHeight="350"
                                                FontFamily="{TemplateBinding FontFamily}"
                                                ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                                ScrollViewer.VerticalScrollBarVisibility="Auto"
                                                VirtualizingStackPanel.IsVirtualizing="True">
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <CheckBox
                                                            x:Name="chkBox"
                                                            Margin="0"
                                                            Checked="SigmaChecked"
                                                            Content="{Binding Name}"
                                                            FontSize="9"
                                                            Foreground="{DynamicResource DynamicAutoFilterForegroundBrushBrush}"
                                                            IsChecked="{Binding IsChecked}"
                                                            Unchecked="SigmaUnChecked" />
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </StackPanel>
                                    </Popup>
                                    <ContentControl
                                        x:Name="autofilter"
                                        Margin="0,0,2,0"
                                        VerticalAlignment="Center"
                                        HorizontalContentAlignment="Stretch"
                                        VerticalContentAlignment="Stretch"
                                        Background="{DynamicResource DynamicAutoFilterBrush}"
                                        BorderBrush="Transparent"
                                        BorderThickness="0"
                                        DockPanel.Dock="Right"
                                        Focusable="True"
                                        Loaded="AutoFilterGlphLoaded"
                                        MouseDown="AutoFilterMouseDown"
                                        MouseRightButtonDown="AutoFilterRightMouseDown"
                                        Style="{x:Null}"
                                        Visibility="Collapsed">

                                        <StackPanel Background="{DynamicResource DynamicHeaderBackgroundBrush}" Orientation="Horizontal">

                                            <Path
                                                Margin="0,0,3,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <Path
                                                HorizontalAlignment="Center"
                                                VerticalAlignment="Center"
                                                Data="M0,0 L8,0 4,4Z"
                                                Fill="{DynamicResource AutoFilterBrush}"
                                                Stroke="Gray" />
                                            <Path
                                                Margin="3,0,0,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </ContentControl>
                                    <ContentControl
                                        x:Name="sigma"
                                        Margin="0,0,2,0"
                                        VerticalAlignment="Center"
                                        HorizontalContentAlignment="Stretch"
                                        VerticalContentAlignment="Stretch"
                                        BorderBrush="Transparent"
                                        BorderThickness="0"
                                        Cursor="Hand"
                                        DockPanel.Dock="Right"
                                        MouseDown="SigmaMouseDown"
                                        MouseRightButtonDown="SigmaRightMouseDown"
                                        Opacity="0.5"
                                        Style="{x:Null}">
                                        <StackPanel Orientation="Horizontal">
                                            <Path
                                                Margin="0,0,1.2,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <ContentControl
                                                Width="15"
                                                Height="12"
                                                ContentTemplate="{DynamicResource SigmaContentTemplate}" />
                                            <!--<Image Height="12" Width="15" RenderOptions.BitmapScalingMode="HighQuality"  Tag="Sigma" Name="SigmaImage"/>-->
                                            <Path
                                                Margin="1.2,0,0,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </ContentControl>
                                    <StackPanel VerticalAlignment="Center" DockPanel.Dock="Right">
                                        <Path
                                            x:Name="SortArrow"
                                            Width="8"
                                            Height="6"
                                            Margin="0,0,7,0"
                                            Data="M0,0 L1,0 0.5,1 z"
                                            Fill="{DynamicResource DynamicSortBrush}"
                                            RenderTransformOrigin="0.5,0.4"
                                            Stretch="Fill"
                                            Tag="{x:Null}"
                                            Visibility="Visible" />
                                        <TextBlock
                                            x:Name="txtSortOrder"
                                            Margin="4.5,-10,7,0"
                                            FontSize="7"
                                            Foreground="{DynamicResource SortOrderForeGroundBrushBrush}"
                                            Visibility="Collapsed">
                                            1
                                        </TextBlock>
                                    </StackPanel>
                                    <ContentControl
                                        x:Name="btnGroupBy"
                                        Width="10"
                                        Height="10"
                                        Margin="3"
                                        DockPanel.Dock="Right">
                                        <ContentControl.Visibility>
                                            <MultiBinding Converter="{StaticResource GroupByButtonVisibilityConverter}">
                                                <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=DataGridColumnHeader}" />
                                                <Binding Path="GroupByCollection" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" />
                                                <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" />
                                            </MultiBinding>
                                        </ContentControl.Visibility>
                                        <Button Click="BtnGroupByClick" ToolTip="Add to group by">
                                            <Path
                                                Data="M3.875,0 L5.125,0 5.125,3.875 9,3.875 9,5.125 5.125,5.125 5.125,9 3.875,9 3.875,5.125 0,5.125 0,3.875 3.875,3.875 3.875,0 z"
                                                Fill="DarkRed"
                                                Stretch="Fill"
                                                Stroke="{x:Null}"
                                                StrokeThickness="0.5" />
                                        </Button>
                                    </ContentControl>



                                    <TextBlock
                                        Margin="4,0,4,0"
                                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                        DockPanel.Dock="Left"
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                        Text="{Binding}" />

                                </DockPanel>
                            </Border>

                        </Themes:DataGridHeaderBorder>

                        <Thumb
                            x:Name="PART_LeftHeaderGripper"
                            HorizontalAlignment="Left"
                            Style="{StaticResource ColumnHeaderRightGripperStyle}" />
                        <Thumb
                            x:Name="PART_RightHeaderGripper"
                            HorizontalAlignment="Right"
                            Style="{StaticResource ColumnHeaderLeftGripperStyle}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <!--  Auto Filter  -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True" />
                                <Condition SourceName="autofilter" Property="IsMouseOver" Value="False" />
                                <Condition SourceName="popupDrag" Property="Tag" Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Background="Transparent" Orientation="Horizontal">

                                            <Path
                                                Margin="0,0,3,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <Path
                                                HorizontalAlignment="Center"
                                                VerticalAlignment="Center"
                                                Data="M0,0 L8,0 4,4Z"
                                                Fill="{DynamicResource AutoFilterBrush}"
                                                Stroke="Gray" />
                                            <Path
                                                Margin="3,0,0,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True" />
                                <Condition SourceName="autofilter" Property="IsMouseOver" Value="True" />
                                <Condition SourceName="popupDrag" Property="Tag" Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Background="Transparent" Orientation="Horizontal">

                                            <Path
                                                Margin="0,0,3,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <Path
                                                HorizontalAlignment="Center"
                                                VerticalAlignment="Center"
                                                Data="M0,0 L8,0 4,4Z"
                                                Fill="{DynamicResource AutoFilterDarkBrush}"
                                                Stroke="{DynamicResource AutoFilterDarkBrush}" />
                                            <Path
                                                Margin="3,0,0,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="False" />
                                <Condition SourceName="autofilter" Property="IsMouseOver" Value="False" />
                                <Condition SourceName="popupDrag" Property="IsOpen" Value="True" />
                                <Condition SourceName="popupDrag" Property="Tag" Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Background="{DynamicResource DynamicHeaderBackgroundBrush}" Orientation="Horizontal">

                                            <Path
                                                Margin="0,0,3,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <Path
                                                HorizontalAlignment="Center"
                                                VerticalAlignment="Center"
                                                Data="M0,0 L8,0 4,4Z"
                                                Fill="{DynamicResource AutoFilterDarkBrush}"
                                                Stroke="{DynamicResource AutoFilterDarkBrush}" />
                                            <Path
                                                Margin="3,0,0,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True" />
                                <Condition SourceName="popupDrag" Property="IsOpen" Value="True" />
                                <Condition SourceName="popupDrag" Property="Tag" Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Background="{DynamicResource DynamicHeaderHighlightedBackgoundBrush}" Orientation="Horizontal">

                                            <Path
                                                Margin="0,0,3,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <Path
                                                HorizontalAlignment="Center"
                                                VerticalAlignment="Center"
                                                Data="M0,0 L8,0 4,4Z"
                                                Fill="{DynamicResource AutoFilterDarkBrush}"
                                                Stroke="{DynamicResource AutoFilterDarkBrush}" />
                                            <Path
                                                Margin="3,0,0,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="popupDrag" Property="Tag" Value="True" />
                                <Condition Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Background="{DynamicResource DynamicHeaderHighlightedBackgoundBrush}" Orientation="Horizontal">

                                            <Path
                                                Margin="0,0,3,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <StackPanel Orientation="Horizontal">
                                                <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                                                    <Path
                                                        HorizontalAlignment="Center"
                                                        Data="M0,0 L6,0 3,3Z"
                                                        Fill="{DynamicResource AutoFilterBrush}"
                                                        Stroke="{DynamicResource AutoFilterDarkBrush}" />
                                                    <Path
                                                        Margin="0,-2,0,0"
                                                        HorizontalAlignment="Center"
                                                        Stroke="{DynamicResource AutoFilterBrush}"
                                                        StrokeThickness="2.5">
                                                        <Path.Data>
                                                            <PathGeometry>
                                                                <PathGeometry.Figures>
                                                                    <PathFigureCollection>
                                                                        <PathFigure StartPoint="0,0">
                                                                            <PathFigure.Segments>
                                                                                <PathSegmentCollection>
                                                                                    <LineSegment Point="0,5" />
                                                                                </PathSegmentCollection>
                                                                            </PathFigure.Segments>
                                                                        </PathFigure>
                                                                    </PathFigureCollection>
                                                                </PathGeometry.Figures>
                                                            </PathGeometry>
                                                        </Path.Data>
                                                    </Path>
                                                </StackPanel>
                                                <Path
                                                    HorizontalAlignment="Center"
                                                    VerticalAlignment="Bottom"
                                                    Data="M0,0 L2,0 1,1Z"
                                                    Fill="{DynamicResource AutoFilterDarkBrush}"
                                                    Stroke="{DynamicResource AutoFilterDarkBrush}" />
                                            </StackPanel>

                                            <Path
                                                Margin="3,0,0,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="popupDrag" Property="Tag" Value="True" />
                                <Condition Property="IsMouseOver" Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Background="{DynamicResource DynamicHeaderBackgroundBrush}" Orientation="Horizontal">

                                            <Path
                                                Margin="0,0,3,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <StackPanel Orientation="Horizontal">
                                                <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                                                    <Path
                                                        HorizontalAlignment="Center"
                                                        Data="M0,0 L6,0 3,3Z"
                                                        Fill="{DynamicResource AutoFilterBrush}"
                                                        Stroke="{DynamicResource AutoFilterDarkBrush}" />
                                                    <Path
                                                        Margin="0,-2,0,0"
                                                        HorizontalAlignment="Center"
                                                        Stroke="{DynamicResource AutoFilterBrush}"
                                                        StrokeThickness="2.5">
                                                        <Path.Data>
                                                            <PathGeometry>
                                                                <PathGeometry.Figures>
                                                                    <PathFigureCollection>
                                                                        <PathFigure StartPoint="0,0">
                                                                            <PathFigure.Segments>
                                                                                <PathSegmentCollection>
                                                                                    <LineSegment Point="0,5" />
                                                                                </PathSegmentCollection>
                                                                            </PathFigure.Segments>
                                                                        </PathFigure>
                                                                    </PathFigureCollection>
                                                                </PathGeometry.Figures>
                                                            </PathGeometry>
                                                        </Path.Data>
                                                    </Path>
                                                </StackPanel>
                                                <Path
                                                    HorizontalAlignment="Center"
                                                    VerticalAlignment="Bottom"
                                                    Data="M0,0 L2,0 1,1Z"
                                                    Fill="{DynamicResource AutoFilterDarkBrush}"
                                                    Stroke="{DynamicResource AutoFilterDarkBrush}" />
                                            </StackPanel>

                                            <Path
                                                Margin="3,0,0,0"
                                                Stroke="{DynamicResource DynamicSeperatorBrush}"
                                                StrokeThickness="1">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                        <!--  Sigma  -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True" />
                                <Condition SourceName="sigma" Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="sigma" Property="Opacity" Value="1" />
                        </MultiTrigger>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=ShowRowSummaries}" Value="False">
                            <Setter TargetName="sigma" Property="Visibility" Value="Collapsed" />
                        </DataTrigger>

                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" Value="{DynamicResource DynamicHeaderHighlightedBackgoundBrush}" />

                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="False">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <!--  Sort Indicator  -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="SortArrow" Property="Tag" Value="{x:Null}" />
                                <Condition Property="SortDirection" Value="Descending" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />

                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="SortArrow" Property="Tag" Value="{x:Null}" />
                                <Condition Property="SortDirection" Value="Ascending" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />

                            <Setter TargetName="SortArrow" Property="RenderTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="180" />
                                </Setter.Value>
                            </Setter>
                        </MultiTrigger>
                        <Trigger Property="SortDirection" Value="{x:Null}">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger SourceName="btnClear" Property="IsEnabled" Value="True">
                            <Setter TargetName="popupDrag" Property="Tag" Value="True" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="SortArrow" Property="Tag" Value="True" />
                                <Condition Property="SortDirection" Value="Descending" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="SortArrow" Property="Data" Value="M0,0 L12,0 6,6Z" />
                            <Setter TargetName="txtSortOrder" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="Fill" Value="{DynamicResource DynamicSortBrush}" />
                            <Setter TargetName="SortArrow" Property="Width" Value="12" />
                            <Setter TargetName="SortArrow" Property="Height" Value="9" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="SortArrow" Property="Tag" Value="True" />
                                <Condition Property="SortDirection" Value="Ascending" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="SortArrow" Property="Data" Value="M0,0 L12,0 6,6Z" />
                            <Setter TargetName="SortArrow" Property="Fill" Value="{DynamicResource DynamicSortBrush}" />
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="RenderTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="180" />
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="txtSortOrder" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="Width" Value="12" />
                            <Setter TargetName="SortArrow" Property="Height" Value="9" />
                        </MultiTrigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" Value="{DynamicResource DynamicHeaderPressedBackgroundBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  DataGridRowSummariesHeader Style  -->


    <!--  DataGridRowHeader Gripper  -->
    <Style x:Key="RowHeaderGripperStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Height" Value="8" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Cursor" Value="SizeNS" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type DataGridRowHeader}" TargetType="{x:Type DataGridRowHeader}">
        <Setter Property="Background" Value="{DynamicResource DynamicHeaderBackgroundBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource DynamicHeaderBorderBrush}" />
        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="PreviewDataCellMouseLeftButtonDown" />
        <EventSetter Event="MouseEnter" Handler="CellMouseEnter" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRowHeader}">
                    <Grid>
                        <Themes:DataGridHeaderBorder
                            x:Name="headerBorder"
                            Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="1,0,1,1"
                            IsHovered="{TemplateBinding IsMouseOver}"
                            IsPressed="{TemplateBinding IsPressed}"
                            IsSelected="{TemplateBinding IsRowSelected}"
                            Orientation="Horizontal"
                            SeparatorBrush="{TemplateBinding SeparatorBrush}"
                            SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
                            <Border BorderBrush="{StaticResource HeaderInnerBorderBrush}" BorderThickness="0,1,0,0">
                                <StackPanel Orientation="Horizontal">
                                    <ContentPresenter VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                    <Control
                                        FontFamily="Arial"
                                        FontSize="9"
                                        SnapsToDevicePixels="false"
                                        Template="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, Path=ValidationErrorTemplate}"
                                        Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, Path=(Validation.HasError), Converter={StaticResource bool2VisibilityConverter}}" />
                                </StackPanel>
                            </Border>
                        </Themes:DataGridHeaderBorder>

                        <Path
                            Name="CurrentRowGlyph"
                            Width="6"
                            Height="10"
                            VerticalAlignment="Center"
                            Data="F1 M 511.047,352.682L 511.047,342.252L 517.145,347.467L 511.047,352.682 Z "
                            Fill="{DynamicResource DynamicHeaderBorderBrush}"
                            Stretch="Fill"
                            Visibility="Collapsed" />
                        <!--<Image x:Name="EditingRowGlyph" Source="../Images/pen_write.png" Width="12" Height="12"  VerticalAlignment="Center" RenderOptions.BitmapScalingMode="HighQuality" Visibility="Collapsed"/>-->
                        <ContentControl
                            x:Name="EditingRowGlyph"
                            Width="12"
                            Height="12"
                            VerticalAlignment="Center"
                            ContentTemplate="{DynamicResource EditingPen}"
                            Visibility="Hidden" />
                        <Thumb
                            x:Name="PART_TopHeaderGripper"
                            VerticalAlignment="Top"
                            Style="{StaticResource RowHeaderGripperStyle}" />
                        <Thumb
                            x:Name="PART_BottomHeaderGripper"
                            VerticalAlignment="Bottom"
                            Style="{StaticResource RowHeaderGripperStyle}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" Value="{DynamicResource DynamicHeaderHighlightedBackgoundBrush}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" Value="{DynamicResource DynamicHeaderPressedBackgroundBrush}" />
                        </Trigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsCurrent}" Value="False" />
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsEditing}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="CurrentRowGlyph" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="EditingRowGlyph" Property="Visibility" Value="Collapsed" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsCurrent}" Value="False" />
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsEditing}" Value="True" />
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="CurrentRowGlyph" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="EditingRowGlyph" Property="Visibility" Value="Visible" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsCurrent}" Value="True" />
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsEditing}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="CurrentRowGlyph" Property="Visibility" Value="Visible" />
                            <Setter TargetName="EditingRowGlyph" Property="Visibility" Value="Collapsed" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsCurrent}" Value="True" />
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsEditing}" Value="True" />
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="CurrentRowGlyph" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="EditingRowGlyph" Property="Visibility" Value="Visible" />
                        </MultiDataTrigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type DataGridCell}">

        <EventSetter Event="MouseEnter" Handler="CellMouseEnter" />
        <Style.Triggers>
            <Trigger Property="DataGridCell.IsSelected" Value="True">
                <Setter Property="Background" Value="{DynamicResource DynamicCurrentRowBackgroundBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    <!--  DataGrid Style  -->
    <Style TargetType="ExtendedGridControl:ExtendedDataGrid">
        <Setter Property="RowBackground" Value="{DynamicResource DynamicRowBackgroundBrush}" />
        <Setter Property="Background" Value="{DynamicResource DynamicDefaultControlBackgroundBrush}" />
        <Setter Property="Foreground" Value="{DynamicResource DynamicDefaultControlForegroundBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource DynamicDefaultControlBorderBrush}" />
        <Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource DynamicGridLineColorBrush}" />
        <Setter Property="VerticalGridLinesBrush" Value="{DynamicResource DynamicGridLineColorBrush}" />
        <Setter Property="CanUserResizeRows" Value="False" />
        <Setter Property="AlternatingRowBackground" Value="{DynamicResource DynamicAlternateRowBackgroundBrush}" />
        <Setter Property="EnableColumnVirtualization" Value="True" />
        <Setter Property="EnableRowVirtualization" Value="True" />
        <Setter Property="ColumnHeaderStyle" Value="{DynamicResource ColumnHeaderStyle}" />
        <Setter Property="BorderThickness" Value="1" />
        <!--  This is needed to force DG to have a non-default value.  Otherwise the DGR.DetailsVisibility cannot have a value of VisibleWhenSelected by default.  -->
        <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected" />
        <Setter Property="ScrollViewer.CanContentScroll" Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ExtendedGridControl:ExtendedDataGrid">
                    <DockPanel>
                        <Popup
                            x:Name="popupDrag"
                            Width="120"
                            AllowsTransparency="True"
                            IsHitTestVisible="False"
                            IsOpen="False"
                            Placement="RelativePoint">
                            <Border
                                Background="{DynamicResource DynamicRowDragBrush}"
                                BorderBrush="{DynamicResource DynamicRowDragBorderBrush}"
                                BorderThickness="1"
                                Opacity="0.9">
                                <StackPanel Margin="4,3,8,3" Orientation="Horizontal">
                                    <Image
                                        Width="16"
                                        Height="16"
                                        Source="../Images/plus.png" />
                                    <TextBlock
                                        Margin="4,0,0,0"
                                        VerticalAlignment="Center"
                                        FontSize="9"
                                        FontWeight="Bold"
                                        Foreground="{DynamicResource DynamicDragForegroundBrush}"
                                        Text="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=DraggedItem[0]}" />
                                </StackPanel>
                            </Border>
                        </Popup>
                        <Border
                            Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="True">
                            <ScrollViewer Name="DG_ScrollViewer" Focusable="false">
                                <ScrollViewer.Template>
                                    <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                        <Grid>
                                            <!--  Drag and Drop Popup  -->

                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto" />
                                                    <RowDefinition Height="*" />
                                                    <RowDefinition Height="Auto" />
                                                    <RowDefinition Height="Auto" />
                                                </Grid.RowDefinitions>

                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="*" />
                                                    <ColumnDefinition Width="Auto" />
                                                </Grid.ColumnDefinitions>

                                                <!--  Left Column Header Corner  -->
                                                <Button
                                                    Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=RowHeaderWidth}"
                                                    HorizontalContentAlignment="Stretch"
                                                    VerticalContentAlignment="Stretch"
                                                    Background="{DynamicResource DynamicHeaderBackgroundBrush}"
                                                    Command="{x:Static DataGrid.SelectAllCommand}"
                                                    Focusable="false"
                                                    Style="{x:Null}"
                                                    Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=HeadersVisibility, Converter={x:Static DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static DataGridHeadersVisibility.All}}">

                                                    <Button.Template>
                                                        <ControlTemplate>
                                                            <Border
                                                                HorizontalAlignment="Stretch"
                                                                VerticalAlignment="Stretch"
                                                                BorderBrush="{DynamicResource DynamicHeaderBorderBrush}"
                                                                BorderThickness="1">

                                                                <Rectangle
                                                                    HorizontalAlignment="Stretch"
                                                                    VerticalAlignment="Stretch"
                                                                    Fill="{DynamicResource DynamicHeaderBackgroundBrush}" />
                                                            </Border>
                                                        </ControlTemplate>
                                                    </Button.Template>
                                                </Button>
                                                <!--  Column Headers  -->
                                                <DockPanel
                                                    x:Name="headerPanel"
                                                    Grid.Row="0"
                                                    Grid.Column="1"
                                                    LastChildFill="True">
                                                    <Popup
                                                        x:Name="columnDragDummy"
                                                        PlacementTarget="{Binding ElementName=headerPanel}"
                                                        StaysOpen="False" />
                                                    <DataGridColumnHeadersPresenter
                                                        x:Name="PART_ColumnHeadersPresenter"
                                                        DockPanel.Dock="Bottom"
                                                        Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=HeadersVisibility, Converter={x:Static DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static DataGridHeadersVisibility.Column}}" />
                                                    <ContentControl
                                                        x:Name="groupByContentControl"
                                                        HorizontalAlignment="Stretch"
                                                        VerticalContentAlignment="Center"
                                                        Background="{DynamicResource DynamicHeaderBackgroundBrush}"
                                                        PreviewMouseDown="RemoveGroupByMouseDown">
                                                        <ContentControl.Resources>
                                                            <Style TargetType="DataGridColumnHeader">
                                                                <!--<Setter Property="IsHitTestVisible" Value="False"/>-->
                                                                <Setter Property="Height" Value="22" />
                                                                <Setter Property="Template">
                                                                    <Setter.Value>
                                                                        <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                                                                            <Border BorderBrush="{DynamicResource DynamicHeaderBorderBrush}" BorderThickness="1">

                                                                                <StackPanel Orientation="Horizontal">
                                                                                    <DockPanel HorizontalAlignment="Stretch" Background="{DynamicResource DynamicHeaderBackgroundBrush}">
                                                                                        <DockPanel.Resources>
                                                                                            <Style TargetType="Button">
                                                                                                <Setter Property="OverridesDefaultStyle" Value="True" />

                                                                                                <Setter Property="Template">
                                                                                                    <Setter.Value>
                                                                                                        <ControlTemplate TargetType="Button">
                                                                                                            <Border
                                                                                                                Name="border"
                                                                                                                Background="{TemplateBinding Background}"
                                                                                                                BorderBrush="Transparent"
                                                                                                                BorderThickness="1"
                                                                                                                CornerRadius="0"
                                                                                                                Opacity="0.5">
                                                                                                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                                                                                                            </Border>
                                                                                                            <ControlTemplate.Triggers>
                                                                                                                <Trigger Property="IsMouseOver" Value="True">
                                                                                                                    <Setter TargetName="border" Property="Opacity" Value="1" />
                                                                                                                </Trigger>
                                                                                                            </ControlTemplate.Triggers>
                                                                                                        </ControlTemplate>
                                                                                                    </Setter.Value>
                                                                                                </Setter>
                                                                                            </Style>
                                                                                        </DockPanel.Resources>
                                                                                        <TextBlock
                                                                                            x:Name="groupName"
                                                                                            Width="Auto"
                                                                                            Margin="0,0,3,0"
                                                                                            HorizontalAlignment="Stretch"
                                                                                            VerticalAlignment="Center"
                                                                                            DockPanel.Dock="Left"
                                                                                            Tag="{Binding SortMemberPath}"
                                                                                            Text="{Binding ColumnName}" />
                                                                                        <Button
                                                                                            x:Name="btnRemove"
                                                                                            Margin="0,0,2,0"
                                                                                            HorizontalAlignment="Right"
                                                                                            VerticalAlignment="Center"
                                                                                            Background="Transparent"
                                                                                            BorderBrush="Transparent"
                                                                                            BorderThickness="1"
                                                                                            Cursor="Hand"
                                                                                            DockPanel.Dock="Right">

                                                                                            <Canvas
                                                                                                Name="canvas"
                                                                                                Width="6"
                                                                                                Height="6">
                                                                                                <Path Stroke="Red" StrokeThickness="1">
                                                                                                    <Path.Data>
                                                                                                        <PathGeometry>
                                                                                                            <PathGeometry.Figures>
                                                                                                                <PathFigure StartPoint="0,0">
                                                                                                                    <LineSegment Point="6,6" />
                                                                                                                </PathFigure>
                                                                                                                <PathFigure StartPoint="0,6">
                                                                                                                    <LineSegment Point="6,0" />
                                                                                                                </PathFigure>
                                                                                                            </PathGeometry.Figures>
                                                                                                        </PathGeometry>
                                                                                                    </Path.Data>
                                                                                                </Path>
                                                                                            </Canvas>
                                                                                        </Button>
                                                                                        <Path
                                                                                            x:Name="SortArrow"
                                                                                            Width="8"
                                                                                            Height="6"
                                                                                            Margin="0,0,7,0"
                                                                                            HorizontalAlignment="Right"
                                                                                            VerticalAlignment="Center"
                                                                                            Data="M0,0 L1,0 0.5,1 z"
                                                                                            DockPanel.Dock="Right"
                                                                                            Fill="{DynamicResource DynamicSortBrush}"
                                                                                            RenderTransformOrigin="0.5,0.4"
                                                                                            Stretch="Fill"
                                                                                            Tag="{x:Null}"
                                                                                            Visibility="Collapsed" />

                                                                                    </DockPanel>

                                                                                </StackPanel>

                                                                            </Border>
                                                                            <ControlTemplate.Triggers>
                                                                                <Trigger Property="Tag" Value="Ascending">
                                                                                    <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                                                                                    <Setter TargetName="SortArrow" Property="RenderTransform">
                                                                                        <Setter.Value>
                                                                                            <RotateTransform Angle="180" />
                                                                                        </Setter.Value>
                                                                                    </Setter>
                                                                                </Trigger>
                                                                                <Trigger Property="Tag" Value="Descending">
                                                                                    <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                                                                                </Trigger>
                                                                            </ControlTemplate.Triggers>
                                                                        </ControlTemplate>

                                                                    </Setter.Value>
                                                                </Setter>
                                                                <EventSetter Event="PreviewMouseDown" Handler="GroupByHeaderPreviewMouseDown" />
                                                            </Style>
                                                        </ContentControl.Resources>
                                                        <StackPanel
                                                            MinHeight="30"
                                                            VerticalAlignment="Center"
                                                            Orientation="Vertical"
                                                            Visibility="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=GroupByControlVisibility}">

                                                            <TextBlock
                                                                x:Name="txtDragName"
                                                                Padding="8"
                                                                VerticalAlignment="Stretch"
                                                                Loaded="TxtDragLoaded"
                                                                Visibility="Visible">
                                                                Click a plus sign in column header to group by that column.
                                                            </TextBlock>

                                                            <DockPanel HorizontalAlignment="Stretch" LastChildFill="True">
                                                                <Button
                                                                    x:Name="btnClearGroup"
                                                                    Margin="3"
                                                                    HorizontalAlignment="Right"
                                                                    VerticalAlignment="Center"
                                                                    Click="ClearGroupClick"
                                                                    Cursor="Hand"
                                                                    DockPanel.Dock="Right"
                                                                    Visibility="Collapsed">
                                                                    <Image
                                                                        Width="12"
                                                                        Height="12"
                                                                        Source="../Images/close.png" />
                                                                </Button>
                                                                <ItemsControl
                                                                    x:Name="group"
                                                                    HorizontalAlignment="Left"
                                                                    VerticalAlignment="Stretch"
                                                                    HorizontalContentAlignment="Left"
                                                                    DockPanel.Dock="Left"
                                                                    ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=GroupByCollection}">
                                                                    <ItemsControl.ItemTemplate>
                                                                        <DataTemplate>
                                                                            <StackPanel Orientation="Horizontal">

                                                                                <Grid
                                                                                    x:Name="Grid"
                                                                                    Width="{Binding GridWidth}"
                                                                                    HorizontalAlignment="Left"
                                                                                    VerticalAlignment="Stretch">
                                                                                    <Grid.RowDefinitions>
                                                                                        <RowDefinition Height="*" />
                                                                                        <RowDefinition Height="*" />
                                                                                    </Grid.RowDefinitions>
                                                                                    <Grid.ColumnDefinitions>
                                                                                        <ColumnDefinition Width="*" />
                                                                                        <ColumnDefinition Width="{Binding GridSecondColumnWidth}" />
                                                                                    </Grid.ColumnDefinitions>
                                                                                    <Border
                                                                                        Grid.Row="0"
                                                                                        Grid.Column="0"
                                                                                        BorderBrush="{DynamicResource DynamicGridLineColorBrush}"
                                                                                        BorderThickness="0,0,1,0" />
                                                                                    <Border
                                                                                        Grid.Row="0"
                                                                                        Grid.Column="1"
                                                                                        BorderBrush="{DynamicResource DynamicGridLineColorBrush}"
                                                                                        BorderThickness="0,0,0,1" />
                                                                                </Grid>
                                                                                <DataGridColumnHeader Width="Auto" Tag="{Binding SortDirection}" />
                                                                            </StackPanel>
                                                                        </DataTemplate>
                                                                    </ItemsControl.ItemTemplate>
                                                                </ItemsControl>

                                                            </DockPanel>
                                                        </StackPanel>
                                                    </ContentControl>

                                                </DockPanel>

                                                <!--  DataGrid content  -->
                                                <DockPanel
                                                    Grid.Row="1"
                                                    Grid.ColumnSpan="2"
                                                    VerticalAlignment="Top"
                                                    LastChildFill="True">

                                                    <ContentControl
                                                        x:Name="footerControlPlacer"
                                                        HorizontalAlignment="Stretch"
                                                        DockPanel.Dock="Bottom">
                                                        <Border
                                                            VerticalAlignment="Bottom"
                                                            BorderBrush="{DynamicResource DynamicHeaderBorderBrush}"
                                                            BorderThickness="1">
                                                            <StackPanel Orientation="Horizontal">

                                                                <Border
                                                                    Width="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=RowHeaderWidth}"
                                                                    HorizontalAlignment="Left"
                                                                    BorderBrush="{DynamicResource DynamicHeaderBorderBrush}"
                                                                    BorderThickness="0,0.5,1,0.5">
                                                                    <Rectangle
                                                                        x:Name="rowSummariesHeader"
                                                                        HorizontalAlignment="Stretch"
                                                                        VerticalAlignment="Stretch"
                                                                        Fill="{DynamicResource DynamicHeaderBackgroundBrush}"
                                                                        Focusable="false"
                                                                        Style="{x:Null}" />

                                                                </Border>
                                                                <ContentControl
                                                                    x:Name="mainFooter"
                                                                    HorizontalAlignment="Left"
                                                                    VerticalAlignment="Stretch"
                                                                    ContentTemplate="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=FooterDataTemplate}" />



                                                            </StackPanel>
                                                        </Border>
                                                    </ContentControl>

                                                    <StackPanel
                                                        x:Name="summaryRow"
                                                        HorizontalAlignment="Left"
                                                        VerticalAlignment="Stretch"
                                                        DockPanel.Dock="Bottom"
                                                        Orientation="Horizontal">
                                                        <Border
                                                            Width="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=RowHeaderWidth}"
                                                            HorizontalAlignment="Left"
                                                            BorderBrush="{DynamicResource DynamicHeaderBorderBrush}"
                                                            BorderThickness="0,0.5,1,0.5">
                                                            <Rectangle
                                                                x:Name="footerHeader"
                                                                HorizontalAlignment="Stretch"
                                                                VerticalAlignment="Stretch"
                                                                Fill="{DynamicResource DynamicHeaderBackgroundBrush}"
                                                                Focusable="false"
                                                                Style="{x:Null}" />

                                                        </Border>
                                                    </StackPanel>

                                                    <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" />

                                                </DockPanel>
                                                <!--  added a grid here for the vertical scroll bar to resize when row freezes  -->
                                                <Grid Grid.Row="1" Grid.Column="2">
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Base:CustomDg}}, Path=NonFrozenRowsViewportVerticalOffset}" />
                                                        <RowDefinition Height="*" />
                                                    </Grid.RowDefinitions>
                                                    <ScrollBar
                                                        Name="PART_VerticalScrollBar"
                                                        Grid.Row="1"
                                                        Maximum="{TemplateBinding ScrollableHeight}"
                                                        Orientation="Vertical"
                                                        ViewportSize="{TemplateBinding ViewportHeight}"
                                                        Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                                                        Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
                                                </Grid>
                                                <StackPanel
                                                    Grid.Row="2"
                                                    Grid.ColumnSpan="3"
                                                    DockPanel.Dock="Bottom"
                                                    Orientation="Horizontal"
                                                    Style="{x:Null}">
                                                    <Border
                                                        Width="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=RowHeaderWidth}"
                                                        HorizontalAlignment="Left"
                                                        BorderBrush="{DynamicResource DynamicHeaderBorderBrush}"
                                                        BorderThickness="0,0.5,1,0.5">
                                                        <Rectangle
                                                            x:Name="rowSummariesHeader1"
                                                            HorizontalAlignment="Stretch"
                                                            VerticalAlignment="Stretch"
                                                            Fill="{DynamicResource DynamicHeaderBackgroundBrush}"
                                                            Focusable="false"
                                                            Style="{x:Null}" />
                                                    </Border>
                                                    <DataGrid
                                                        x:Name="rowSummariesGrid"
                                                        Width="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=ActualWidth}"
                                                        BorderBrush="{DynamicResource DynamicHeaderBorderBrush}"
                                                        BorderThickness="0,1,1,1"
                                                        CanUserAddRows="False"
                                                        CanUserDeleteRows="False"
                                                        CanUserReorderColumns="False"
                                                        CanUserResizeColumns="False"
                                                        CanUserResizeRows="False"
                                                        CanUserSortColumns="False"
                                                        HeadersVisibility="Column"
                                                        IsReadOnly="True"
                                                        Loaded="RowSummariesGridLoaded"
                                                        RowHeight="0"
                                                        ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                                                        Style="{x:Null}" />
                                                </StackPanel>
                                                <Grid Grid.Row="3" Grid.Column="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=NonFrozenColumnsViewportHorizontalOffset}" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>

                                                    <ScrollBar
                                                        Name="PART_HorizontalScrollBar"
                                                        Grid.Column="1"
                                                        VerticalAlignment="Bottom"
                                                        Maximum="{TemplateBinding ScrollableWidth}"
                                                        Orientation="Horizontal"
                                                        Scroll="OnScroll"
                                                        ViewportSize="{TemplateBinding ViewportWidth}"
                                                        Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                                                        Value="{Binding Path=HorizontalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
                                                </Grid>

                                            </Grid>
                                            <Rectangle
                                                Width="7"
                                                HorizontalAlignment="Left"
                                                Fill="{DynamicResource AutoFilterBrush}"
                                                Loaded="DummyGridSplitterLoaded"
                                                Visibility="Collapsed" />
                                            <Grid Loaded="GridSplitterGridLoaded">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="0" />
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition />
                                                </Grid.ColumnDefinitions>

                                                <GridSplitter
                                                    x:Name="gridSplitter"
                                                    Grid.Column="1"
                                                    Width="7"
                                                    Cursor="SizeWE"
                                                    Loaded="GridSplitterLoaded"
                                                    PreviewMouseDown="GridSplitterMouseDown"
                                                    PreviewMouseUp="GridSplitterMouseUp"
                                                    ResizeBehavior="PreviousAndNext"
                                                    ShowsPreview="False"
                                                    Visibility="Visible">
                                                    <GridSplitter.Resources>
                                                        <Style TargetType="{x:Type GridSplitter}">
                                                            <Setter Property="PreviewStyle">
                                                                <Setter.Value>
                                                                    <Style>
                                                                        <Setter Property="Control.Template">
                                                                            <Setter.Value>
                                                                                <ControlTemplate>
                                                                                    <Rectangle Fill="#80000000" />
                                                                                </ControlTemplate>
                                                                            </Setter.Value>
                                                                        </Setter>
                                                                    </Style>
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Setter Property="Template">
                                                                <Setter.Value>
                                                                    <ControlTemplate TargetType="{x:Type GridSplitter}">
                                                                        <Border BorderThickness="{TemplateBinding BorderThickness}" />
                                                                    </ControlTemplate>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Style>
                                                    </GridSplitter.Resources>
                                                    <GridSplitter.Template>
                                                        <ControlTemplate TargetType="{x:Type GridSplitter}">
                                                            <Grid VerticalAlignment="Stretch">
                                                                <Button
                                                                    Margin="-0.3,0,0,0"
                                                                    VerticalAlignment="Stretch"
                                                                    VerticalContentAlignment="Top"
                                                                    Background="#DDE0E3"
                                                                    BorderBrush="Transparent"
                                                                    BorderThickness="0"
                                                                    Content="⁞" />
                                                                <Rectangle VerticalAlignment="Stretch" Fill="Transparent" />
                                                            </Grid>
                                                        </ControlTemplate>
                                                    </GridSplitter.Template>
                                                </GridSplitter>
                                            </Grid>
                                            <Rectangle
                                                x:Name="rowSplitter"
                                                Height="2"
                                                HorizontalAlignment="Stretch"
                                                VerticalAlignment="Top"
                                                Fill="{DynamicResource AutoFilterBrush}"
                                                Loaded="RowSplitterLoaded"
                                                Visibility="Collapsed" />
                                        </Grid>
                                    </ControlTemplate>
                                </ScrollViewer.Template>
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </ScrollViewer>
                        </Border>
                    </DockPanel>

                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <!--  Event Setters  -->
        <EventSetter Event="Loaded" Handler="GridLoaded" />
        <EventSetter Event="MouseMove" Handler="GridMouseMove" />
        <EventSetter Event="PreviewMouseLeftButtonUp" Handler="GridPreviewMouseLeftButtonUp" />
        <EventSetter Event="MouseLeave" Handler="GridMouseLeave" />
        <Style.Triggers>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false" />
            </Trigger>
        </Style.Triggers>

    </Style>

</ResourceDictionary>