<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:bpa="clr-namespace:BPA.UIControl"
                    xmlns:converters="clr-namespace:BPA.UIControl.Converters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/ScrollViewer.xaml" />
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/CheckBox.xaml" />
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/ComboBox.xaml" />
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/ToggleButton.xaml" />
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/Loading.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <!--  Style and template for the DataGridCell.  -->
    <Style x:Key="RubyerDataGridCell" TargetType="{x:Type DataGridCell}">
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Padding" Value="{Binding Path=(bpa:ItemsControlHelper.ItemPadding), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridCell}">
                    <Grid>
                        <bpa:ControlMask x:Name="mask"
                                         Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                         CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                         IsActive="{TemplateBinding IsSelected}"
                                         MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                         Visibility="Visible" />

                        <Border x:Name="border"
                                Background="Transparent"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <ContentPresenter Margin="{TemplateBinding Padding}"
                                              HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                              VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Border>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Foreground" Value="{Binding Path=(bpa:ControlHelper.FocusedForegroundBrush), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
                        </Trigger>
                        <DataTrigger Binding="{Binding SelectionUnit, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="FullRow">
                            <Setter TargetName="mask" Property="Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  Style and template for the resize control on the DataGridRowHeader.  -->
    <Style x:Key="RowHeaderGripperStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Height" Value="5" />
        <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 and template for the DataGridRowHeader.  -->
    <Style x:Key="RubyerDataGridRowHeader" TargetType="{x:Type DataGridRowHeader}">
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="BorderBrush" Value="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRowHeader}">
                    <Grid>
                        <Border x:Name="rowHeaderBorder"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <StackPanel Margin="{Binding Path=(bpa:ItemsControlHelper.ItemPadding), RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                        HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                        VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                        Orientation="Horizontal">
                                <Control Margin="0 0 3 0"
                                         SnapsToDevicePixels="False"
                                         Template="{Binding ValidationErrorTemplate, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}"
                                         Visibility="{Binding Path=(Validation.HasError), Converter={StaticResource BooleanToVisibleConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" />
                                <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </StackPanel>
                        </Border>

                        <Thumb x:Name="PART_TopHeaderGripper"
                               Style="{StaticResource RowHeaderGripperStyle}"
                               VerticalAlignment="Top" />
                        <Thumb x:Name="PART_BottomHeaderGripper"
                               Style="{StaticResource RowHeaderGripperStyle}"
                               VerticalAlignment="Bottom" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="All">
                            <Setter Property="BorderThickness" Value="0 0 1 1" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="Vertical">
                            <Setter Property="BorderThickness" Value="0 0 1 0" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="Horizontal">
                            <Setter Property="BorderThickness" Value="0 0 0 1" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>



    <!--  Style and template for the DataGridRow.  -->
    <Style x:Key="RubyerDataGridRow" TargetType="{x:Type DataGridRow}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderBrush" Value="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
        <Setter Property="DetailsVisibility" Value="Collapsed" />
        <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">
                        <Grid>
                            <bpa:ControlMask Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                             CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                             IsActive="{TemplateBinding IsSelected}"
                                             MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource AncestorType=DataGrid}}" />

                            <SelectiveScrollingGrid>
                                <SelectiveScrollingGrid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </SelectiveScrollingGrid.ColumnDefinitions>
                                <SelectiveScrollingGrid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </SelectiveScrollingGrid.RowDefinitions>

                                <DataGridRowHeader Grid.RowSpan="2"
                                                   SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
                                                   Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />

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

                                <bpa:Transition Grid.Row="1"
                                                Grid.Column="1"
                                                IsShow="{TemplateBinding DetailsVisibility, Converter={StaticResource VisibilityToBooleanConverter}}"
                                                Type="CollapseUp">
                                    <DataGridDetailsPresenter SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
                                </bpa:Transition>

                            </SelectiveScrollingGrid>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Foreground" Value="{Binding Path=(bpa:ControlHelper.FocusedForegroundBrush), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  Style and template for the resize control on the DataGridColumnHeader.  -->
    <Style x:Key="ColumnHeaderGripperStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Cursor" Value="SizeWE" />
        <Setter Property="Width" Value="5" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  Style and template for the DataGridColumnHeader.  -->
    <Style x:Key="RubyerDataGridColumnHeader" TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{Binding Path=(bpa:HeaderHelper.Foreground), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="HorizontalContentAlignment" Value="{Binding Path=(bpa:HeaderHelper.HorizontalAlignment), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="VerticalContentAlignment" Value="{Binding Path=(bpa:HeaderHelper.VerticalAlignment), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="Padding" Value="{Binding Path=(bpa:HeaderHelper.Padding), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="FontSize" Value="{Binding Path=(bpa:HeaderHelper.FontSize), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="FontWeight" Value="{Binding Path=(bpa:HeaderHelper.FontWeight), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="FontFamily" Value="{Binding Path=(bpa:HeaderHelper.FontFamily), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                    <Grid>
                        <Border x:Name="columnHeaderBorder"
                                Padding="{TemplateBinding Padding}"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                BorderThickness="0">
                            <StackPanel HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                        Orientation="Horizontal">
                                <ContentPresenter Grid.Column="1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

                                <bpa:Icon x:Name="arrow"
                                          Foreground="{TemplateBinding Foreground}"
                                          RenderTransformOrigin="0.5,0.5"
                                          Type="ArrowDownSLine"
                                          Visibility="Collapsed">
                                    <bpa:Icon.RenderTransform>
                                        <RotateTransform x:Name="arrowTransform" Angle="0" />
                                    </bpa:Icon.RenderTransform>
                                </bpa:Icon>
                            </StackPanel>
                        </Border>
                        <Thumb x:Name="PART_LeftHeaderGripper"
                               Style="{StaticResource ColumnHeaderGripperStyle}"
                               HorizontalAlignment="Left" />
                        <Thumb x:Name="PART_RightHeaderGripper"
                               Style="{StaticResource ColumnHeaderGripperStyle}"
                               HorizontalAlignment="Right" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="Vertical">
                            <Setter TargetName="columnHeaderBorder" Property="BorderThickness" Value="0 0 1 0" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="Horizontal">
                            <Setter TargetName="columnHeaderBorder" Property="BorderThickness" Value="0 0 0 1" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="All">
                            <Setter TargetName="columnHeaderBorder" Property="BorderThickness" Value="0 0 1 1" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding SortDirection, RelativeSource={RelativeSource Self}}" Value="Descending">
                            <Setter TargetName="arrow" Property="Visibility" Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding SortDirection, RelativeSource={RelativeSource Self}}" Value="Ascending">
                            <Setter TargetName="arrow" Property="Visibility" Value="Visible" />
                            <DataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowTransform"
                                                         Storyboard.TargetProperty="Angle"
                                                         From="0"
                                                         To="180"
                                                         Duration="0:0:0.3" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowTransform"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="0"
                                                         Duration="0:0:0.3" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="FirstDataGridColumnHeader"
           BasedOn="{StaticResource RubyerDataGridColumnHeader}"
           TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Background" Value="{Binding Path=(bpa:HeaderHelper.Background), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                    <Border x:Name="columnHeaderBorder"
                            Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=DataGrid}}">
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Border>

                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="Vertical">
                            <Setter TargetName="columnHeaderBorder" Property="BorderThickness" Value="0 0 1 0" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="Horizontal">
                            <Setter TargetName="columnHeaderBorder" Property="BorderThickness" Value="0 0 0 1" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="All">
                            <Setter TargetName="columnHeaderBorder" Property="BorderThickness" Value="0 0 1 1" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <converters:GetDataGridColumnCheckedContentConverter x:Key="GetDataGridColumnCheckedContent" />

    <Style x:Key="DataGridSelectCheckBoxColumnHeader"
           BasedOn="{StaticResource RubyerDataGridColumnHeader}"
           TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                    <Border x:Name="columnHeaderBorder"
                            Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=DataGrid}}"
                            BorderThickness="0">

                        <StackPanel HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Orientation="Horizontal">
                            <CheckBox bpa:DataGridHelper.IsHeaderSelectCheckBox="True"
                                      Content="{TemplateBinding Content}"
                                      Foreground="{TemplateBinding Foreground}">
                                <bpa:ToggleButtonHelper.CheckedContent>
                                    <MultiBinding Converter="{StaticResource GetDataGridColumnCheckedContent}" Mode="OneWay">
                                        <Binding RelativeSource="{RelativeSource AncestorType=DataGrid}" />
                                        <Binding RelativeSource="{RelativeSource AncestorType=DataGridColumnHeader}" />
                                    </MultiBinding>
                                </bpa:ToggleButtonHelper.CheckedContent>
                            </CheckBox>
                        </StackPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="Vertical">
                            <Setter TargetName="columnHeaderBorder" Property="BorderThickness" Value="0 0 1 0" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="Horizontal">
                            <Setter TargetName="columnHeaderBorder" Property="BorderThickness" Value="0 0 0 1" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding GridLinesVisibility, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="All">
                            <Setter TargetName="columnHeaderBorder" Property="BorderThickness" Value="0 0 1 1" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  Style and template for the DataGridColumnHeadersPresenter.  -->
    <Style x:Key="RubyerDataGridColumnHeadersPresenter" TargetType="{x:Type DataGridColumnHeadersPresenter}">
        <Setter Property="Background" Value="{Binding Path=(bpa:HeaderHelper.Background), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeadersPresenter}">
                    <Grid Background="{TemplateBinding Background}">
                        <DataGridColumnHeader x:Name="PART_FillerColumnHeader" IsHitTestVisible="False" />
                        <ItemsPresenter />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <bpa:Icon x:Key="DataGridRowHeaderTitleIcon"
              x:Shared="False"
              Type="GridFill" />

    <!--  Style and template for the DataGrid.  -->
    <Style x:Key="RubyerDataGrid" TargetType="{x:Type DataGrid}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderBrush" Value="{DynamicResource Border}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="CellStyle" Value="{StaticResource RubyerDataGridCell}" />
        <Setter Property="ColumnHeaderStyle" Value="{StaticResource RubyerDataGridColumnHeader}" />
        <Setter Property="RowHeaderStyle" Value="{StaticResource RubyerDataGridRowHeader}" />
        <Setter Property="RowStyle" Value="{StaticResource RubyerDataGridRow}" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="GridLinesVisibility" Value="Horizontal" />
        <Setter Property="HeadersVisibility" Value="Column" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="HorizontalGridLinesBrush" Value="{Binding BorderBrush, RelativeSource={RelativeSource Self}}" />
        <Setter Property="VerticalGridLinesBrush" Value="{Binding BorderBrush, RelativeSource={RelativeSource Self}}" />
        <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected" />
        <Setter Property="ScrollViewer.CanContentScroll" Value="True" />
        <Setter Property="ScrollViewer.PanningMode" Value="Both" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="RowDetailsVisibilityMode" Value="Collapsed" />
        <Setter Property="Validation.ErrorTemplate" Value="{StaticResource MouseOverValidationErrorTemplate}" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="0" />
        <Setter Property="bpa:ControlHelper.MaskOpacity" Value="0.6" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Mask}" />
        <Setter Property="bpa:ControlHelper.FocusedForegroundBrush" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="bpa:HeaderHelper.Background" Value="{DynamicResource HeaderBackground}" />
        <Setter Property="bpa:HeaderHelper.Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="bpa:HeaderHelper.FontSize" Value="{Binding FontSize, RelativeSource={RelativeSource Self}}" />
        <Setter Property="bpa:HeaderHelper.FontWeight" Value="Bold" />
        <Setter Property="bpa:HeaderHelper.HorizontalAlignment" Value="Left" />
        <Setter Property="bpa:HeaderHelper.VerticalAlignment" Value="Center" />
        <Setter Property="bpa:HeaderHelper.Padding" Value="10 8" />
        <Setter Property="bpa:ItemsControlHelper.ItemPadding" Value="5" />
        <Setter Property="bpa:DataGridHelper.ApplyColumnElementStyle" Value="True" />
        <Setter Property="bpa:DataGridHelper.ClickToEdit" Value="True" />
        <Setter Property="bpa:DataGridHelper.ApplyDataAnnotations" Value="True" />
        <Setter Property="bpa:DataGridHelper.LoadingContent" Value="{DynamicResource I18N_DataGrid_LoadingContent}" />
        <Setter Property="bpa:DataGridHelper.EmptyView">
            <Setter.Value>
                <StackPanel HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Orientation="Horizontal">
                    <bpa:Icon Margin="5 0" Type="DatabaseFill" />
                    <TextBlock Text="{DynamicResource I18N_DataGrid_NoData}" />
                </StackPanel>
            </Setter.Value>
        </Setter>
        <Setter Property="bpa:DataGridHelper.RowHeaderTitle" Value="{StaticResource DataGridRowHeaderTitleIcon}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGrid}">
                    <Border x:Name="border"
                            Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="True">
                        <ScrollViewer x:Name="DG_ScrollViewer"
                                      Style="{StaticResource RubyerScrollViewer}"
                                      Background="Transparent"
                                      Focusable="False">
                            <ScrollViewer.Template>
                                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                    <Grid x:Name="root">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>


                                        <DataGridColumnHeader Style="{StaticResource FirstDataGridColumnHeader}"
                                                              Width="{Binding RowHeaderActualWidth, RelativeSource={RelativeSource AncestorType=DataGrid}}"
                                                              Command="DataGrid.SelectAllCommand"
                                                              Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}">
                                            <ContentControl Content="{Binding Path=(bpa:DataGridHelper.RowHeaderTitle), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
                                        </DataGridColumnHeader>

                                        <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter"
                                                                        Style="{StaticResource RubyerDataGridColumnHeadersPresenter}"
                                                                        Grid.Column="1"
                                                                        Grid.ColumnSpan="2"
                                                                        Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Column}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
                                        <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                                                Grid.Row="1"
                                                                Grid.RowSpan="2"
                                                                Grid.ColumnSpan="3"
                                                                CanContentScroll="{TemplateBinding CanContentScroll}" />

                                        <ScrollBar x:Name="PART_VerticalScrollBar"
                                                   Style="{StaticResource RubyerScrollBar}"
                                                   Grid.Row="1"
                                                   Grid.Column="2"
                                                   Maximum="{TemplateBinding ScrollableHeight}"
                                                   Orientation="Vertical"
                                                   ViewportSize="{TemplateBinding ViewportHeight}"
                                                   Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                                                   Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />

                                        <ScrollBar x:Name="PART_HorizontalScrollBar"
                                                   Style="{StaticResource RubyerScrollBar}"
                                                   Grid.Row="2"
                                                   Grid.ColumnSpan="2"
                                                   Maximum="{TemplateBinding ScrollableWidth}"
                                                   Orientation="Horizontal"
                                                   ViewportSize="{TemplateBinding ViewportWidth}"
                                                   Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                                                   Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />

                                        <Border x:Name="emptyBorder"
                                                Grid.Row="1"
                                                Grid.ColumnSpan="3"
                                                Visibility="Collapsed">
                                            <ContentControl x:Name="emptyView" Content="{Binding Path=(bpa:DataGridHelper.EmptyView), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
                                        </Border>

                                        <Border x:Name="loadingBorder"
                                                Grid.Row="1"
                                                Grid.ColumnSpan="3"
                                                Background="{DynamicResource DialogBackground}"
                                                Visibility="Collapsed">
                                            <bpa:Card Padding="10"
                                                      HorizontalAlignment="Center"
                                                      VerticalAlignment="Center">
                                                <bpa:Loading x:Name="loading"
                                                             Background="Transparent"
                                                             Content="{Binding Path=(bpa:DataGridHelper.LoadingContent), RelativeSource={RelativeSource AncestorType=DataGrid}}" />
                                            </bpa:Card>
                                        </Border>
                                    </Grid>
                                    <ControlTemplate.Triggers>
                                        <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Mode=TemplatedParent}}" Value="0">
                                            <Setter TargetName="emptyBorder" Property="Visibility" Value="Visible" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding Path=(bpa:DataGridHelper.Loading), RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="True">
                                            <Setter TargetName="loadingBorder" Property="Visibility" Value="Visible" />
                                        </DataTrigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </ScrollViewer.Template>

                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsGrouping" Value="True">
                <Setter Property="ScrollViewer.CanContentScroll" Value="False" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Opacity" Value="{DynamicResource UnenableOpcity}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="RubyerDataGridTextColumn"
           BasedOn="{StaticResource RubyerTextBox}"
           TargetType="{x:Type TextBox}">
        <Setter Property="Padding" Value="0 2" />
    </Style>

    <Style x:Key="RubyerDataGridCheckBoxColumn"
           BasedOn="{StaticResource RubyerCheckBox}"
           TargetType="{x:Type CheckBox}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="HorizontalAlignment" Value="Center" />
        <Setter Property="IsHitTestVisible" Value="False" />
    </Style>

    <Style x:Key="RubyerDataGridCheckBoxColumnEditting"
           BasedOn="{StaticResource RubyerCheckBox}"
           TargetType="{x:Type CheckBox}">
        <Setter Property="HorizontalAlignment" Value="Center" />
    </Style>

    <Style x:Key="RubyerDataGridComboBoxColumnEditting"
           BasedOn="{StaticResource RubyerComboBox}"
           TargetType="{x:Type ComboBox}">
        <Setter Property="Padding" Value="0 3" />
    </Style>

    <Style x:Key="RubyerDataGridDetailToggleButtonColumn" TargetType="{x:Type ToggleButton}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="HorizontalAlignment" Value="Center" />
        <Setter Property="IsHitTestVisible" Value="False" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource AncestorType=DataGridCell}}" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="Padding" Value="5 0" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="IsChecked" Value="{Binding DetailsVisibility, RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={StaticResource VisibilityToBooleanConverter}}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border x:Name="border"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <bpa:Icon RenderTransformOrigin="0.5 0.5" Type="ArrowDownSLine">
                            <bpa:Icon.RenderTransform>
                                <RotateTransform x:Name="arrowTransform" Angle="0" />
                            </bpa:Icon.RenderTransform>
                        </bpa:Icon>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Opacity" Value="{DynamicResource UnenableOpcity}" />
                        </Trigger>
                        <Trigger Property="IsChecked" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowTransform"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="-180"
                                                         Duration="0:0:0.25">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowTransform"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="0"
                                                         Duration="0:0:0.25">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>