Переглянути джерело

Add DataGrid fluent controltheme

# Conflicts:
#	src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml
Max Katz 3 роки тому
батько
коміт
6e59fe347e

+ 5 - 4
samples/ControlCatalog/Pages/DataGridPage.xaml

@@ -10,11 +10,11 @@
         <TextBlock Text="{Binding}"/>
       </StackPanel>
     </DataTemplate>
+    <ControlTheme x:Key="GdpCell" TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
+      <Setter Property="Background" Value="{Binding Path=GDP, Mode=OneWay, Converter={StaticResource GDPConverter}}" />
+    </ControlTheme>
   </UserControl.Resources>
   <UserControl.Styles>
-    <Style Selector="DataGridCell.gdp">
-      <Setter Property="Background" Value="{Binding Path=GDP, Mode=OneWay, Converter={StaticResource GDPConverter}}" />
-    </Style>
     <Style Selector="DataGridColumnHeader:nth-last-child(1)">
       <Setter Property="FontWeight" Value="Bold" />
     </Style>
@@ -54,7 +54,8 @@
               <DataGridTextColumn Header="Region" Binding="{CompiledBinding Region}" Width="4*" x:DataType="local:Country" />
               <DataGridTextColumn Header="Population" Binding="{Binding Population}" Width="3*" />
               <DataGridTextColumn Header="Area" Binding="{Binding Area}" Width="3*" />
-              <DataGridTextColumn Header="GDP" Binding="{Binding GDP}" Width="3*" CellStyleClasses="gdp"
+              <DataGridTextColumn Header="GDP" Binding="{Binding GDP}" Width="3*"
+                                  CellTheme="{StaticResource GdpCell}"
                                   MinWidth="200"
                                   IsVisible="{Binding #ShowGDP.IsChecked}"/>
             </DataGrid.Columns>

+ 9 - 1
src/Avalonia.Controls.DataGrid/DataGridCell.cs

@@ -14,7 +14,7 @@ namespace Avalonia.Controls
     /// Represents an individual <see cref="T:Avalonia.Controls.DataGrid" /> cell.
     /// </summary>
     [TemplatePart(DATAGRIDCELL_elementRightGridLine, typeof(Rectangle))]
-    [PseudoClasses(":selected", ":current", ":edited", ":invalid")]
+    [PseudoClasses(":selected", ":current", ":edited", ":invalid", ":focus")]
     public class DataGridCell : ContentControl
     {
         private const string DATAGRIDCELL_elementRightGridLine = "PART_RightGridLine";
@@ -216,6 +216,8 @@ namespace Avalonia.Controls
             PseudoClasses.Set(":edited", IsEdited);
 
             PseudoClasses.Set(":invalid", !IsValid);
+            
+            PseudoClasses.Set(":focus", OwningGrid.IsFocused && IsCurrent);
         }
 
         // Makes sure the right gridline has the proper stroke and visibility. If lastVisibleColumn is specified, the 
@@ -245,9 +247,15 @@ namespace Avalonia.Controls
             if (column == null)
             {
                 Classes.Clear();
+                ClearValue(ThemeProperty);
             }
             else
             {
+                if (Theme != column.CellTheme)
+                {
+                    Theme = column.CellTheme;
+                }
+                
                 Classes.Replace(column.CellStyleClasses);
             }
         }

+ 20 - 0
src/Avalonia.Controls.DataGrid/DataGridColumn.cs

@@ -16,6 +16,7 @@ using Avalonia.Controls.Templates;
 using Avalonia.Controls.Utils;
 using Avalonia.Layout;
 using Avalonia.Markup.Xaml.MarkupExtensions;
+using Avalonia.Styling;
 
 namespace Avalonia.Controls
 {
@@ -36,6 +37,7 @@ namespace Avalonia.Controls
         private IControl _editingElement;
         private ICellEditBinding _editBinding;
         private IBinding _clipboardContentBinding;
+        private ControlTheme _cellTheme;
         private readonly Classes _cellStyleClasses = new Classes();
 
         /// <summary>
@@ -399,6 +401,24 @@ namespace Avalonia.Controls
                 }
             }
         }
+        
+        /// <summary>
+        ///    Backing field for CellTheme property.
+        /// </summary>
+        public static readonly DirectProperty<DataGridColumn, ControlTheme> CellThemeProperty =
+            AvaloniaProperty.RegisterDirect<DataGridColumn, ControlTheme>(
+                nameof(CellTheme),
+                o => o.CellTheme,
+                (o, v) => o.CellTheme = v);
+
+        /// <summary>
+        ///    Gets or sets the <see cref="DataGridColumnHeader"/> cell theme. 
+        /// </summary>
+        public ControlTheme CellTheme
+        {
+            get { return _cellTheme; }
+            set { SetAndRaise(CellThemeProperty, ref _cellTheme, value); }
+        }
 
         /// <summary>
         ///    Backing field for Header property

+ 0 - 1
src/Avalonia.Controls.DataGrid/DataGridRowGroupHeader.cs

@@ -113,7 +113,6 @@ namespace Avalonia.Controls
         /// </summary>
         public DataGridRowGroupHeader()
         {
-            //DefaultStyleKey = typeof(DataGridRowGroupHeader);
             AddHandler(InputElement.PointerPressedEvent, (s, e) => DataGridRowGroupHeader_PointerPressed(e), handledEventsToo: true);
         }
 

+ 22 - 6
src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs

@@ -11,6 +11,7 @@ using System.ComponentModel;
 using Avalonia.Layout;
 using Avalonia.Markup.Xaml.MarkupExtensions;
 using Avalonia.Controls.Documents;
+using Avalonia.Styling;
 
 namespace Avalonia.Controls
 {
@@ -19,12 +20,20 @@ namespace Avalonia.Controls
     /// </summary>
     public class DataGridTextColumn : DataGridBoundColumn
     {
+        private readonly Lazy<ControlTheme> _cellTextBoxTheme;
+        private readonly Lazy<ControlTheme> _cellTextBlockTheme;
+        
         /// <summary>
         /// Initializes a new instance of the <see cref="T:Avalonia.Controls.DataGridTextColumn" /> class.
         /// </summary>
         public DataGridTextColumn()
         {
             BindingTarget = TextBox.TextProperty;
+
+            _cellTextBoxTheme = new Lazy<ControlTheme>(() =>
+                OwningGrid.TryFindResource("DataGridCellTextBoxTheme", out var theme) ? (ControlTheme)theme : null);
+            _cellTextBlockTheme = new Lazy<ControlTheme>(() =>
+                OwningGrid.TryFindResource("DataGridCellTextBlockTheme", out var theme) ? (ControlTheme)theme : null);
         }
 
         /// <summary>
@@ -156,16 +165,19 @@ namespace Avalonia.Controls
         protected override IControl GenerateEditingElementDirect(DataGridCell cell, object dataItem)
         {
             var textBox = new TextBox
-            {
-                VerticalAlignment = VerticalAlignment.Stretch,
-                Background = new SolidColorBrush(Colors.Transparent)
+            {                
+                Name = "CellTextBox"
             };
+            if (_cellTextBoxTheme.Value is { } theme)
+            {
+                textBox.Theme = theme;
+            }
 
             SyncProperties(textBox);
 
             return textBox;
         }
-
+        
         /// <summary>
         /// Gets a read-only <see cref="T:Avalonia.Controls.TextBlock" /> element that is bound to the column's <see cref="P:Avalonia.Controls.DataGridBoundColumn.Binding" /> property value.
         /// </summary>
@@ -174,10 +186,14 @@ namespace Avalonia.Controls
         /// <returns>A new, read-only <see cref="T:Avalonia.Controls.TextBlock" /> element that is bound to the column's <see cref="P:Avalonia.Controls.DataGridBoundColumn.Binding" /> property value.</returns>
         protected override IControl GenerateElement(DataGridCell cell, object dataItem)
         {
-            TextBlock textBlockElement = new TextBlock
+            var textBlockElement = new TextBlock
             {
                 Name = "CellTextBlock"
             };
+            if (_cellTextBlockTheme.Value is { } theme)
+            {
+                textBlockElement.Theme = theme;
+            }
 
             SyncProperties(textBlockElement);
 
@@ -227,7 +243,7 @@ namespace Avalonia.Controls
         {
             if (element == null)
             {
-                throw new ArgumentNullException("element");
+                throw new ArgumentNullException(nameof(element));
             }
 
             if (element is AvaloniaObject content)

+ 503 - 575
src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml

@@ -1,8 +1,8 @@
-<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        x:CompileBindings="True">
   <Styles.Resources>
     <x:Double x:Key="ListAccentLowOpacity">0.6</x:Double>
     <x:Double x:Key="ListAccentMediumOpacity">0.8</x:Double>
-    <Thickness x:Key="DataGridTextColumnCellTextBlockMargin">12,0,12,0</Thickness>
 
     <StreamGeometry x:Key="DataGridSortIconDescendingPath">M1875 1011l-787 787v-1798h-128v1798l-787 -787l-90 90l941 941l941 -941z</StreamGeometry>
     <StreamGeometry x:Key="DataGridSortIconAscendingPath">M1965 947l-941 -941l-941 941l90 90l787 -787v1798h128v-1798l787 787z</StreamGeometry>
@@ -13,10 +13,12 @@
     <SolidColorBrush x:Key="DataGridColumnHeaderBackgroundBrush" Color="{DynamicResource SystemAltHighColor}" />
     <SolidColorBrush x:Key="DataGridColumnHeaderHoveredBackgroundBrush" Color="{DynamicResource SystemListLowColor}" />
     <SolidColorBrush x:Key="DataGridColumnHeaderPressedBackgroundBrush" Color="{DynamicResource SystemListMediumColor}" />
-    <SolidColorBrush x:Key="DataGridColumnHeaderDraggedBackgroundBrush" Color="{DynamicResource SystemChromeMediumLowColor}" />
+    <SolidColorBrush x:Key="DataGridColumnHeaderDraggedBackgroundBrush"
+                     Color="{DynamicResource SystemChromeMediumLowColor}" />
 
     <SolidColorBrush x:Key="DataGridRowGroupHeaderBackgroundBrush" Color="{DynamicResource SystemChromeMediumColor}" />
-    <SolidColorBrush x:Key="DataGridRowGroupHeaderPressedBackgroundBrush" Color="{DynamicResource SystemListMediumColor}" />
+    <SolidColorBrush x:Key="DataGridRowGroupHeaderPressedBackgroundBrush"
+                     Color="{DynamicResource SystemListMediumColor}" />
     <SolidColorBrush x:Key="DataGridRowGroupHeaderForegroundBrush" Color="{DynamicResource SystemBaseHighColor}" />
     <SolidColorBrush x:Key="DataGridRowGroupHeaderHoveredBackgroundBrush" Color="{DynamicResource SystemListLowColor}" />
 
@@ -27,14 +29,12 @@
     <StaticResource x:Key="DataGridRowSelectedHoveredBackgroundOpacity" ResourceKey="ListAccentMediumOpacity" />
     <SolidColorBrush x:Key="DataGridRowSelectedUnfocusedBackgroundBrush" Color="{DynamicResource SystemAccentColor}" />
     <StaticResource x:Key="DataGridRowSelectedUnfocusedBackgroundOpacity" ResourceKey="ListAccentLowOpacity" />
-    <SolidColorBrush x:Key="DataGridRowSelectedHoveredUnfocusedBackgroundBrush" Color="{DynamicResource SystemAccentColor}" />
+    <SolidColorBrush x:Key="DataGridRowSelectedHoveredUnfocusedBackgroundBrush"
+                     Color="{DynamicResource SystemAccentColor}" />
     <StaticResource x:Key="DataGridRowSelectedHoveredUnfocusedBackgroundOpacity" ResourceKey="ListAccentMediumOpacity" />
     <SolidColorBrush x:Key="DataGridRowHoveredBackgroundColor" Color="{DynamicResource SystemListLowColor}" />
     <SolidColorBrush x:Key="DataGridRowInvalidBrush" Color="{DynamicResource SystemErrorTextColor}" />
-
-    <SolidColorBrush x:Key="DataGridRowHeaderForegroundBrush" Color="{DynamicResource SystemBaseMediumColor}" />
-    <SolidColorBrush x:Key="DataGridRowHeaderBackgroundBrush" Color="{DynamicResource SystemAltHighColor}" />
-
+    
     <StaticResource x:Key="DataGridCellBackgroundBrush" ResourceKey="SystemControlTransparentBrush" />
     <SolidColorBrush x:Key="DataGridCellFocusVisualPrimaryBrush" Color="{DynamicResource SystemBaseHighColor}" />
     <SolidColorBrush x:Key="DataGridCellFocusVisualSecondaryBrush" Color="{DynamicResource SystemAltMediumColor}" />
@@ -44,157 +44,425 @@
                      Opacity="0.4"
                      Color="{DynamicResource SystemBaseMediumLowColor}" />
     <StaticResource x:Key="DataGridCurrencyVisualPrimaryBrush" ResourceKey="SystemControlTransparentBrush" />
-    <SolidColorBrush x:Key="DataGridDetailsPresenterBackgroundBrush" Color="{DynamicResource SystemChromeMediumLowColor}" />
+    <SolidColorBrush x:Key="DataGridDetailsPresenterBackgroundBrush"
+                     Color="{DynamicResource SystemChromeMediumLowColor}" />
     <StaticResource x:Key="DataGridFillerColumnGridLinesBrush" ResourceKey="SystemControlTransparentBrush" />
-  </Styles.Resources>
 
-  <Style Selector="DataGridCell">
-    <Setter Property="Background" Value="{DynamicResource DataGridCellBackgroundBrush}" />
-    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
-    <Setter Property="VerticalContentAlignment" Value="Stretch" />
-    <Setter Property="FontSize" Value="15" />
-    <Setter Property="MinHeight" Value="32" />
-    <Setter Property="Focusable" Value="False" />
-    <Setter Property="Template">
-      <ControlTemplate>
-        <Border x:Name="CellBorder"
-                Background="{TemplateBinding Background}"
-                BorderBrush="{TemplateBinding BorderBrush}"
-                BorderThickness="{TemplateBinding BorderThickness}"
-                CornerRadius="{TemplateBinding CornerRadius}">
-          <Grid x:Name="PART_CellRoot" ColumnDefinitions="*,Auto">
-
-            <Rectangle x:Name="CurrencyVisual"
-                       HorizontalAlignment="Stretch"
-                       VerticalAlignment="Stretch"
-                       Fill="Transparent"
-                       IsHitTestVisible="False"
-                       Stroke="{DynamicResource DataGridCurrencyVisualPrimaryBrush}"
-                       StrokeThickness="1" />
-            <Grid x:Name="FocusVisual" IsHitTestVisible="False">
-              <Rectangle HorizontalAlignment="Stretch"
+    <ControlTheme x:Key="DataGridCellTextBlockTheme" TargetType="TextBlock">
+      <Setter Property="Margin" Value="12,0,12,0" />
+      <Setter Property="VerticalAlignment" Value="Center" />
+    </ControlTheme>
+    <ControlTheme x:Key="DataGridCellTextBoxTheme" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
+      <Setter Property="Margin" Value="12,0,12,0" />
+      <Setter Property="VerticalAlignment" Value="Stretch" />
+      <Setter Property="Background" Value="Transparent" />
+      <Style Selector="^ /template/ DataValidationErrors">
+        <Setter Property="Template" Value="{DynamicResource TooltipDataValidationContentTemplate}" />
+        <Setter Property="ErrorTemplate" Value="{DynamicResource TooltipDataValidationErrorTemplate}" />
+      </Style>
+    </ControlTheme>
+
+    <ControlTheme x:Key="{x:Type DataGridCell}" TargetType="DataGridCell">
+      <Setter Property="Background" Value="{DynamicResource DataGridCellBackgroundBrush}" />
+      <Setter Property="HorizontalContentAlignment" Value="Stretch" />
+      <Setter Property="VerticalContentAlignment" Value="Stretch" />
+      <Setter Property="FontSize" Value="15" />
+      <Setter Property="MinHeight" Value="32" />
+      <Setter Property="Focusable" Value="False" />
+      <Setter Property="Template">
+        <ControlTemplate>
+          <Border x:Name="CellBorder"
+                  Background="{TemplateBinding Background}"
+                  BorderBrush="{TemplateBinding BorderBrush}"
+                  BorderThickness="{TemplateBinding BorderThickness}"
+                  CornerRadius="{TemplateBinding CornerRadius}">
+            <Grid x:Name="PART_CellRoot" ColumnDefinitions="*,Auto">
+
+              <Rectangle x:Name="CurrencyVisual"
+                         IsVisible="False"
+                         HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
                          Fill="Transparent"
                          IsHitTestVisible="False"
-                         Stroke="{DynamicResource DataGridCellFocusVisualPrimaryBrush}"
-                         StrokeThickness="2" />
-              <Rectangle Margin="2"
+                         Stroke="{DynamicResource DataGridCurrencyVisualPrimaryBrush}"
+                         StrokeThickness="1" />
+              <Grid Grid.Column="0" x:Name="FocusVisual" IsHitTestVisible="False"
+                    IsVisible="False">
+                <Rectangle HorizontalAlignment="Stretch"
+                           VerticalAlignment="Stretch"
+                           Fill="Transparent"
+                           IsHitTestVisible="False"
+                           Stroke="{DynamicResource DataGridCellFocusVisualPrimaryBrush}"
+                           StrokeThickness="2" />
+                <Rectangle Margin="2"
+                           HorizontalAlignment="Stretch"
+                           VerticalAlignment="Stretch"
+                           Fill="Transparent"
+                           IsHitTestVisible="False"
+                           Stroke="{DynamicResource DataGridCellFocusVisualSecondaryBrush}"
+                           StrokeThickness="1" />
+              </Grid>
+
+              <ContentPresenter Grid.Column="0" Margin="{TemplateBinding Padding}"
+                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
+                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
+                                Content="{TemplateBinding Content}"
+                                ContentTemplate="{TemplateBinding ContentTemplate}"
+                                Foreground="{TemplateBinding Foreground}" />
+
+              <Rectangle Grid.Column="0" x:Name="InvalidVisualElement"
+                         IsVisible="False"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
-                         Fill="Transparent"
                          IsHitTestVisible="False"
-                         Stroke="{DynamicResource DataGridCellFocusVisualSecondaryBrush}"
+                         Stroke="{DynamicResource DataGridCellInvalidBrush}"
                          StrokeThickness="1" />
-            </Grid>
 
-            <ContentPresenter Margin="{TemplateBinding Padding}"
-                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
-                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
-                              Content="{TemplateBinding Content}"
-                              ContentTemplate="{TemplateBinding ContentTemplate}"
-                              Foreground="{TemplateBinding Foreground}" />
+              <Rectangle Name="PART_RightGridLine"
+                         Grid.Column="1"
+                         Width="1"
+                         VerticalAlignment="Stretch"
+                         Fill="{DynamicResource DataGridFillerColumnGridLinesBrush}" />
+            </Grid>
+          </Border>
+        </ControlTemplate>
+      </Setter>
+      <Style Selector="^:current /template/ Rectangle#CurrencyVisual">
+        <Setter Property="IsVisible" Value="True" />
+      </Style>
+      <Style Selector="^:focus /template/ Grid#FocusVisual">
+        <Setter Property="IsVisible" Value="True" />
+      </Style>
+      <Style Selector="^:invalid /template/ Rectangle#InvalidVisualElement">
+        <Setter Property="IsVisible" Value="True" />
+      </Style>
+    </ControlTheme>
+
+    <ControlTheme x:Key="{x:Type DataGridColumnHeader}" TargetType="DataGridColumnHeader">
+      <Setter Property="Foreground" Value="{DynamicResource DataGridColumnHeaderForegroundBrush}" />
+      <Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderBackgroundBrush}" />
+      <Setter Property="HorizontalContentAlignment" Value="Stretch" />
+      <Setter Property="VerticalContentAlignment" Value="Center" />
+      <Setter Property="Focusable" Value="False" />
+      <Setter Property="SeparatorBrush" Value="{DynamicResource DataGridGridLinesBrush}" />
+      <Setter Property="Padding" Value="12,0,0,0" />
+      <Setter Property="FontSize" Value="12" />
+      <Setter Property="MinHeight" Value="32" />
+      <Setter Property="Template">
+        <ControlTemplate>
+          <Border x:Name="HeaderBorder"
+                  Background="{TemplateBinding Background}"
+                  BorderBrush="{TemplateBinding BorderBrush}"
+                  BorderThickness="{TemplateBinding BorderThickness}"
+                  CornerRadius="{TemplateBinding CornerRadius}">
+            <Grid Name="PART_ColumnHeaderRoot" ColumnDefinitions="*,Auto">
+
+              <Grid Margin="{TemplateBinding Padding}"
+                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
+                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
+                <Grid.ColumnDefinitions>
+                  <ColumnDefinition Width="*" />
+                  <ColumnDefinition Width="Auto" MinWidth="32" />
+                </Grid.ColumnDefinitions>
+
+                <ContentPresenter Content="{TemplateBinding Content}"
+                                  ContentTemplate="{TemplateBinding ContentTemplate}" />
+
+                <Path Name="SortIcon"
+                      IsVisible="False"
+                      Grid.Column="1"
+                      Height="12"
+                      HorizontalAlignment="Center"
+                      VerticalAlignment="Center"
+                      Fill="{TemplateBinding Foreground}"
+                      Stretch="Uniform" />
+              </Grid>
 
-            <Rectangle x:Name="InvalidVisualElement"
+              <Rectangle Name="VerticalSeparator"
+                         Grid.Column="1"
+                         Width="1"
+                         VerticalAlignment="Stretch"
+                         Fill="{TemplateBinding SeparatorBrush}"
+                         IsVisible="{TemplateBinding AreSeparatorsVisible}" />
+
+              <Grid x:Name="FocusVisual" IsHitTestVisible="False"
+                    IsVisible="False">
+                <Rectangle x:Name="FocusVisualPrimary"
+                           HorizontalAlignment="Stretch"
+                           VerticalAlignment="Stretch"
+                           Fill="Transparent"
+                           IsHitTestVisible="False"
+                           Stroke="{DynamicResource DataGridCellFocusVisualPrimaryBrush}"
+                           StrokeThickness="2" />
+                <Rectangle x:Name="FocusVisualSecondary"
+                           Margin="2"
+                           HorizontalAlignment="Stretch"
+                           VerticalAlignment="Stretch"
+                           Fill="Transparent"
+                           IsHitTestVisible="False"
+                           Stroke="{DynamicResource DataGridCellFocusVisualSecondaryBrush}"
+                           StrokeThickness="1" />
+              </Grid>
+            </Grid>
+          </Border>
+        </ControlTemplate>
+      </Setter>
+
+      <Style Selector="^:focus-visible /template/ Grid#FocusVisual">
+        <Setter Property="IsVisible" Value="True" />
+      </Style>
+
+      <Style Selector="^:pointerover /template/ Grid#PART_ColumnHeaderRoot">
+        <Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderHoveredBackgroundBrush}" />
+      </Style>
+
+      <Style Selector="^:pressed /template/ Grid#PART_ColumnHeaderRoot">
+        <Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderPressedBackgroundBrush}" />
+      </Style>
+
+      <Style Selector="^:dragIndicator">
+        <Setter Property="Opacity" Value="0.5" />
+      </Style>
+
+      <Style Selector="^:sortascending /template/ Path#SortIcon">
+        <Setter Property="IsVisible" Value="True" />
+        <Setter Property="Data" Value="{StaticResource DataGridSortIconAscendingPath}" />
+      </Style>
+
+      <Style Selector="^:sortdescending /template/ Path#SortIcon">
+        <Setter Property="IsVisible" Value="True" />
+        <Setter Property="Data" Value="{StaticResource DataGridSortIconDescendingPath}" />
+      </Style>
+    </ControlTheme>
+    
+    <ControlTheme x:Key="DataGridTopLeftColumnHeader" TargetType="DataGridColumnHeader" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
+      <Setter Property="Template">
+        <ControlTemplate>
+          <Grid x:Name="TopLeftHeaderRoot"
+                RowDefinitions="*,*,Auto">
+            <Border Grid.RowSpan="2"
+                    BorderThickness="0,0,1,0"
+                    BorderBrush="{DynamicResource DataGridGridLinesBrush}" />
+            <Rectangle Grid.Row="0" Grid.RowSpan="2"
+                       VerticalAlignment="Bottom"
+                       StrokeThickness="1"
+                       Height="1"
+                       Fill="{DynamicResource DataGridGridLinesBrush}" />
+          </Grid>
+        </ControlTemplate>
+      </Setter>
+    </ControlTheme>
+
+    <ControlTheme x:Key="{x:Type DataGridRowHeader}" TargetType="DataGridRowHeader">
+      <Setter Property="Focusable" Value="False" />
+      <Setter Property="SeparatorBrush" Value="{DynamicResource DataGridGridLinesBrush}" />
+      <Setter Property="AreSeparatorsVisible" Value="False" />
+      <Setter Property="Template">
+        <ControlTemplate>
+          <Grid x:Name="PART_Root"
+                RowDefinitions="*,*,Auto"
+                ColumnDefinitions="Auto,*">
+            <Border Grid.RowSpan="3"
+                    Grid.ColumnSpan="2"
+                    BorderBrush="{TemplateBinding SeparatorBrush}"
+                    BorderThickness="0,0,1,0">
+              <Grid Background="{TemplateBinding Background}">
+                <Rectangle x:Name="RowInvalidVisualElement"
+                           Opacity="0"
+                           Fill="{DynamicResource DataGridRowInvalidBrush}"
+                           Stretch="Fill" />
+                <Rectangle x:Name="BackgroundRectangle"
+                           Fill="{DynamicResource DataGridRowBackgroundBrush}"
+                           Stretch="Fill" />
+              </Grid>
+            </Border>
+            <Rectangle x:Name="HorizontalSeparator"
+                       Grid.Row="2"
+                       Grid.ColumnSpan="2"
+                       Height="1"
+                       Margin="1,0,1,0"
                        HorizontalAlignment="Stretch"
-                       VerticalAlignment="Stretch"
-                       IsHitTestVisible="False"
-                       Stroke="{DynamicResource DataGridCellInvalidBrush}"
-                       StrokeThickness="1" />
+                       Fill="{TemplateBinding SeparatorBrush}"
+                       IsVisible="{TemplateBinding AreSeparatorsVisible}" />
 
-            <Rectangle Name="PART_RightGridLine"
-                       Grid.Column="1"
-                       Width="1"
-                       VerticalAlignment="Stretch"
-                       Fill="{DynamicResource DataGridFillerColumnGridLinesBrush}" />
+            <ContentPresenter Grid.RowSpan="2"
+                              Grid.Column="1"
+                              HorizontalAlignment="Center"
+                              VerticalAlignment="Center"
+                              Content="{TemplateBinding Content}" />
           </Grid>
-        </Border>
-      </ControlTemplate>
-    </Setter>
-  </Style>
-
-  <Style Selector="DataGridCell > TextBlock#CellTextBlock">
-    <Setter Property="Margin" Value="{DynamicResource DataGridTextColumnCellTextBlockMargin}" />
-    <Setter Property="VerticalAlignment" Value="Center" />
-  </Style>
-  
-  <Style Selector="DataGridCell /template/ Rectangle#CurrencyVisual">
-    <Setter Property="IsVisible" Value="False" />
-  </Style>
-  <Style Selector="DataGridCell /template/ Grid#FocusVisual">
-    <Setter Property="IsVisible" Value="False" />
-  </Style>
-  <Style Selector="DataGridCell:current /template/ Rectangle#CurrencyVisual">
-    <Setter Property="IsVisible" Value="True" />
-  </Style>
-  <Style Selector="DataGrid:focus DataGridCell:current /template/ Grid#FocusVisual">
-    <Setter Property="IsVisible" Value="True" />
-  </Style>
-  <Style Selector="DataGridCell /template/ Rectangle#InvalidVisualElement">
-    <Setter Property="IsVisible" Value="False" />
-  </Style>
-  <Style Selector="DataGridCell:invalid /template/ Rectangle#InvalidVisualElement">
-    <Setter Property="IsVisible" Value="True" />
-  </Style>
-  <Style Selector="DataGridCell > TextBox DataValidationErrors">
-    <Setter Property="Template" Value="{DynamicResource TooltipDataValidationContentTemplate}" />
-    <Setter Property="ErrorTemplate" Value="{DynamicResource TooltipDataValidationErrorTemplate}" />
-  </Style>
-
-  <Style Selector="DataGridColumnHeader">
-    <Setter Property="Foreground" Value="{DynamicResource DataGridColumnHeaderForegroundBrush}" />
-    <Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderBackgroundBrush}" />
-    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
-    <Setter Property="VerticalContentAlignment" Value="Center" />
-    <Setter Property="Focusable" Value="False" />
-    <Setter Property="SeparatorBrush" Value="{DynamicResource DataGridGridLinesBrush}" />
-    <Setter Property="Padding" Value="12,0,0,0" />
-    <Setter Property="FontSize" Value="12" />
-    <Setter Property="MinHeight" Value="32" />
-    <Setter Property="Template">
-      <ControlTemplate>
-        <Border x:Name="HeaderBorder"
-                Background="{TemplateBinding Background}"
-                BorderBrush="{TemplateBinding BorderBrush}"
-                BorderThickness="{TemplateBinding BorderThickness}"
-                CornerRadius="{TemplateBinding CornerRadius}">
-          <Grid Name="PART_ColumnHeaderRoot" ColumnDefinitions="*,Auto">
-
-            <Grid Margin="{TemplateBinding Padding}"
-                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
-                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
-              <Grid.ColumnDefinitions>
-                <ColumnDefinition Width="*" />
-                <ColumnDefinition Width="Auto" MinWidth="32" />
-              </Grid.ColumnDefinitions>
-
-              <ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
-
-              <Path Name="SortIcon"
-                    Grid.Column="1"
-                    Height="12"
-                    HorizontalAlignment="Center"
-                    VerticalAlignment="Center"
-                    Fill="{TemplateBinding Foreground}"
-                    Stretch="Uniform" />
-            </Grid>
+        </ControlTemplate>
+      </Setter>
+    </ControlTheme>
+
+    <ControlTheme x:Key="{x:Type DataGridRow}" TargetType="DataGridRow">
+      <Setter Property="Focusable" Value="False" />
+      <Setter Property="Background" Value="{Binding $parent[DataGrid].RowBackground}" />
+      <Setter Property="Template">
+        <ControlTemplate>
+          <Border x:Name="RowBorder"
+                  Background="{TemplateBinding Background}"
+                  BorderBrush="{TemplateBinding BorderBrush}"
+                  BorderThickness="{TemplateBinding BorderThickness}"
+                  CornerRadius="{TemplateBinding CornerRadius}">
+            <DataGridFrozenGrid Name="PART_Root"
+                                ColumnDefinitions="Auto,*"
+                                RowDefinitions="*,Auto,Auto">
+
+              <Rectangle Name="BackgroundRectangle"
+                         Fill="{DynamicResource DataGridRowBackgroundBrush}"
+                         Grid.RowSpan="2"
+                         Grid.ColumnSpan="2" />
+              <Rectangle x:Name="InvalidVisualElement"
+                         Opacity="0"
+                         Grid.ColumnSpan="2"
+                         Fill="{DynamicResource DataGridRowInvalidBrush}" />
+
+              <DataGridRowHeader Name="PART_RowHeader"
+                                 Grid.RowSpan="3"
+                                 DataGridFrozenGrid.IsFrozen="True" />
+              <DataGridCellsPresenter Name="PART_CellsPresenter"
+                                      Grid.Column="1"
+                                      DataGridFrozenGrid.IsFrozen="True" />
+              <DataGridDetailsPresenter Name="PART_DetailsPresenter"
+                                        Grid.Row="1"
+                                        Grid.Column="1"
+                                        Background="{DynamicResource DataGridDetailsPresenterBackgroundBrush}" />
+              <Rectangle Name="PART_BottomGridLine"
+                         Grid.Row="2"
+                         Grid.Column="1"
+                         Height="1"
+                         HorizontalAlignment="Stretch" />
 
-            <Rectangle Name="VerticalSeparator"
-                       Grid.Column="1"
-                       Width="1"
-                       VerticalAlignment="Stretch"
-                       Fill="{TemplateBinding SeparatorBrush}"
-                       IsVisible="{TemplateBinding AreSeparatorsVisible}" />
+            </DataGridFrozenGrid>
+          </Border>
+        </ControlTemplate>
+      </Setter>
+
+      <Style Selector="^:nth-child(even)">
+        <Setter Property="Background" Value="{Binding $parent[DataGrid].AlternatingRowBackground}" />
+      </Style>
+
+      <Style Selector="^:invalid">
+        <Style Selector="^ /template/ Rectangle#InvalidVisualElement">
+          <Setter Property="Opacity" Value="0.4" />
+        </Style>
+        <Style Selector="^ /template/ Rectangle#BackgroundRectangle">
+          <Setter Property="Opacity" Value="0" />
+        </Style>
+      </Style>
+
+      <Style Selector="^:pointerover /template/ Rectangle#BackgroundRectangle">
+        <Setter Property="Fill" Value="{DynamicResource DataGridRowHoveredBackgroundColor}" />
+      </Style>
+
+      <Style Selector="^:selected">
+        <Style Selector="^ /template/ Rectangle#BackgroundRectangle">
+          <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundBrush}" />
+          <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundOpacity}" />
+        </Style>
+        <Style Selector="^:pointerover /template/ Rectangle#BackgroundRectangle">
+          <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundBrush}" />
+          <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundOpacity}" />
+        </Style>
+        <Style Selector="^:focus /template/ Rectangle#BackgroundRectangle">
+          <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedBackgroundBrush}" />
+          <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedBackgroundOpacity}" />
+        </Style>
+        <Style Selector="^:pointerover:focus /template/ Rectangle#BackgroundRectangle">
+          <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundBrush}" />
+          <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundOpacity}" />
+        </Style>
+      </Style>
+    </ControlTheme>
+
+    <ControlTheme x:Key="FluentDataGridRowGroupExpanderButtonTheme" TargetType="ToggleButton">
+      <Setter Property="Template">
+        <ControlTemplate>
+          <Border Width="12"
+                  Height="12"
+                  Background="Transparent"
+                  HorizontalAlignment="Center"
+                  VerticalAlignment="Center">
+            <Path Fill="{TemplateBinding Foreground}"
+                  Data="{StaticResource DataGridRowGroupHeaderIconOpenedPath}"
+                  HorizontalAlignment="Right"
+                  VerticalAlignment="Center"
+                  Stretch="Uniform" />
+          </Border>
+        </ControlTemplate>
+      </Setter>
+      <Style Selector="^:checked /template/ Path">
+        <Setter Property="Data" Value="{StaticResource DataGridRowGroupHeaderIconClosedPath}" />
+      </Style>
+    </ControlTheme>
+
+    <ControlTheme x:Key="{x:Type DataGridRowGroupHeader}" TargetType="DataGridRowGroupHeader">
+      <Setter Property="Focusable" Value="False" />
+      <Setter Property="Foreground" Value="{DynamicResource DataGridRowGroupHeaderForegroundBrush}" />
+      <Setter Property="Background" Value="{DynamicResource DataGridRowGroupHeaderBackgroundBrush}" />
+      <Setter Property="FontSize" Value="15" />
+      <Setter Property="MinHeight" Value="32" />
+      <Setter Property="Template">
+        <ControlTemplate>
+          <DataGridFrozenGrid Name="PART_Root"
+                              Background="{TemplateBinding Background}"
+                              MinHeight="{TemplateBinding MinHeight}"
+                              ColumnDefinitions="Auto,Auto,Auto,Auto,*"
+                              RowDefinitions="*,Auto">
+
+            <Rectangle Name="IndentSpacer"
+                       Grid.Column="1" />
+            <ToggleButton Name="ExpanderButton"
+                          Grid.Column="2"
+                          Width="12"
+                          Height="12"
+                          Margin="12,0,0,0"
+                          Theme="{StaticResource FluentDataGridRowGroupExpanderButtonTheme}"
+                          BorderBrush="{TemplateBinding BorderBrush}"
+                          BorderThickness="{TemplateBinding BorderThickness}"
+                          Background="{TemplateBinding Background}"
+                          CornerRadius="{TemplateBinding CornerRadius}"
+                          Focusable="False"
+                          Foreground="{TemplateBinding Foreground}" />
+
+            <StackPanel Grid.Column="3"
+                        Orientation="Horizontal"
+                        VerticalAlignment="Center"
+                        Margin="12,0,0,0">
+              <TextBlock Name="PropertyNameElement"
+                         Margin="4,0,0,0"
+                         IsVisible="{TemplateBinding IsPropertyNameVisible}"
+                         Foreground="{TemplateBinding Foreground}" />
+              <TextBlock Margin="4,0,0,0"
+                         Text="{ReflectionBinding Key}"
+                         Foreground="{TemplateBinding Foreground}" />
+              <TextBlock Name="ItemCountElement"
+                         Margin="4,0,0,0"
+                         IsVisible="{TemplateBinding IsItemCountVisible}"
+                         Foreground="{TemplateBinding Foreground}" />
+            </StackPanel>
 
-            <Grid x:Name="FocusVisual" IsHitTestVisible="False">
-              <Rectangle x:Name="FocusVisualPrimary"
-                         HorizontalAlignment="Stretch"
+            <Rectangle x:Name="CurrencyVisual"
+                       Grid.ColumnSpan="5"
+                       IsVisible="False"
+                       HorizontalAlignment="Stretch"
+                       VerticalAlignment="Stretch"
+                       Fill="Transparent"
+                       IsHitTestVisible="False"
+                       Stroke="{DynamicResource DataGridCurrencyVisualPrimaryBrush}"
+                       StrokeThickness="1" />
+            <Grid x:Name="FocusVisual"
+                  Grid.ColumnSpan="5"
+                  IsVisible="False"
+                  IsHitTestVisible="False">
+              <Rectangle HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
                          Fill="Transparent"
                          IsHitTestVisible="False"
                          Stroke="{DynamicResource DataGridCellFocusVisualPrimaryBrush}"
                          StrokeThickness="2" />
-              <Rectangle x:Name="FocusVisualSecondary"
-                         Margin="2"
+              <Rectangle Margin="2"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
                          Fill="Transparent"
@@ -202,447 +470,107 @@
                          Stroke="{DynamicResource DataGridCellFocusVisualSecondaryBrush}"
                          StrokeThickness="1" />
             </Grid>
-          </Grid>
-        </Border>
-      </ControlTemplate>
-    </Setter>
-  </Style>
-
-  <Style Selector="DataGridColumnHeader /template/ Grid#FocusVisual">
-    <Setter Property="IsVisible" Value="False" />
-  </Style>
-  <Style Selector="DataGridColumnHeader:focus-visible /template/ Grid#FocusVisual">
-    <Setter Property="IsVisible" Value="True" />
-  </Style>
-
-  <Style Selector="DataGridColumnHeader:pointerover /template/ Grid#PART_ColumnHeaderRoot">
-    <Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderHoveredBackgroundBrush}" />
-  </Style>
-  <Style Selector="DataGridColumnHeader:pressed /template/ Grid#PART_ColumnHeaderRoot">
-    <Setter Property="Background" Value="{DynamicResource DataGridColumnHeaderPressedBackgroundBrush}" />
-  </Style>
-
-  <Style Selector="DataGridColumnHeader:dragIndicator">
-    <Setter Property="Opacity" Value="0.5" />
-  </Style>
-
-  <Style Selector="DataGridColumnHeader /template/ Path#SortIcon">
-    <Setter Property="IsVisible" Value="False" />
-  </Style>
-
-  <Style Selector="DataGridColumnHeader:sortascending /template/ Path#SortIcon">
-    <Setter Property="IsVisible" Value="True" />
-    <Setter Property="Data" Value="{StaticResource DataGridSortIconAscendingPath}" />
-  </Style>
-
-  <Style Selector="DataGridColumnHeader:sortdescending /template/ Path#SortIcon">
-    <Setter Property="IsVisible" Value="True" />
-    <Setter Property="Data" Value="{StaticResource DataGridSortIconDescendingPath}" />
-  </Style>
-
-  <Style Selector="DataGridRow">
-    <Setter Property="Focusable" Value="False" />
-    <Setter Property="Template">
-      <ControlTemplate>
-        <Border x:Name="RowBorder"
-                Background="{TemplateBinding Background}"
-                BorderBrush="{TemplateBinding BorderBrush}"
-                BorderThickness="{TemplateBinding BorderThickness}"
-                CornerRadius="{TemplateBinding CornerRadius}">
-          <DataGridFrozenGrid Name="PART_Root"
-                              ColumnDefinitions="Auto,*"
-                              RowDefinitions="*,Auto,Auto">
-
-            <Rectangle Name="BackgroundRectangle"
-                       Grid.RowSpan="2"
-                       Grid.ColumnSpan="2" />
-            <Rectangle x:Name="InvalidVisualElement"
-                       Grid.ColumnSpan="2"
-                       Fill="{DynamicResource DataGridRowInvalidBrush}" />
 
             <DataGridRowHeader Name="PART_RowHeader"
-                               Grid.RowSpan="3"
+                               Grid.RowSpan="2"
                                DataGridFrozenGrid.IsFrozen="True" />
-            <DataGridCellsPresenter Name="PART_CellsPresenter"
-                                    Grid.Column="1"
-                                    DataGridFrozenGrid.IsFrozen="True" />
-            <DataGridDetailsPresenter Name="PART_DetailsPresenter"
-                                      Grid.Row="1"
-                                      Grid.Column="1"
-                                      Background="{DynamicResource DataGridDetailsPresenterBackgroundBrush}" />
-            <Rectangle Name="PART_BottomGridLine"
-                       Grid.Row="2"
-                       Grid.Column="1"
-                       Height="1"
-                       HorizontalAlignment="Stretch" />
 
+            <Rectangle x:Name="PART_BottomGridLine"
+                       Grid.Row="1"
+                       Grid.ColumnSpan="5"
+                       Height="1" />
           </DataGridFrozenGrid>
-        </Border>
-      </ControlTemplate>
-    </Setter>
-  </Style>
-
-  <Style Selector="DataGridRow">
-    <Setter Property="Background" Value="{Binding $parent[DataGrid].RowBackground}" />
-  </Style>
-  <Style Selector="DataGridRow:nth-child(even)">
-    <Setter Property="Background" Value="{Binding $parent[DataGrid].AlternatingRowBackground}" />
-  </Style>
-
-  <Style Selector="DataGridRow /template/ Rectangle#InvalidVisualElement">
-    <Setter Property="Opacity" Value="0" />
-  </Style>
-  <Style Selector="DataGridRow:invalid /template/ Rectangle#InvalidVisualElement">
-    <Setter Property="Opacity" Value="0.4" />
-  </Style>
-  <Style Selector="DataGridRow:invalid /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Opacity" Value="0" />
-  </Style>
-
-  <Style Selector="DataGridRow /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowBackgroundBrush}" />
-  </Style>
-  <Style Selector="DataGridRow:pointerover /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowHoveredBackgroundColor}" />
-  </Style>
-  <Style Selector="DataGridRow:selected /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundBrush}" />
-    <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundOpacity}" />
-  </Style>
-  <Style Selector="DataGridRow:selected:pointerover /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundBrush}" />
-    <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundOpacity}" />
-  </Style>
-  <Style Selector="DataGridRow:selected:focus /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedBackgroundBrush}" />
-    <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedBackgroundOpacity}" />
-  </Style>
-  <Style Selector="DataGridRow:selected:pointerover:focus /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundBrush}" />
-    <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundOpacity}" />
-  </Style>
-
-  <Style Selector="DataGridRowHeader">
-    <Setter Property="Foreground" Value="{DynamicResource DataGridRowHeaderForegroundBrush}" />
-    <Setter Property="Background" Value="{DynamicResource DataGridRowHeaderBackgroundBrush}" />
-    <Setter Property="Focusable" Value="False" />
-    <Setter Property="SeparatorBrush" Value="{DynamicResource DataGridGridLinesBrush}" />
-    <Setter Property="AreSeparatorsVisible" Value="False" />
-    <Setter Property="Template">
-      <ControlTemplate>
-        <Grid x:Name="PART_Root"
-              RowDefinitions="*,*,Auto"
-              ColumnDefinitions="Auto,*">
-          <Border Grid.RowSpan="3"
-                  Grid.ColumnSpan="2"
-                  BorderBrush="{TemplateBinding SeparatorBrush}"
-                  BorderThickness="0,0,1,0">
-            <Grid Background="{TemplateBinding Background}">
-              <Rectangle x:Name="RowInvalidVisualElement"
-                         Fill="{DynamicResource DataGridRowInvalidBrush}"
-                         Stretch="Fill" />
-              <Rectangle x:Name="BackgroundRectangle"
-                         Stretch="Fill" />
+        </ControlTemplate>
+      </Setter>
+    </ControlTheme>
+
+    <ControlTheme x:Key="{x:Type DataGrid}" TargetType="DataGrid">
+      <Setter Property="RowBackground" Value="Transparent" />
+      <Setter Property="AlternatingRowBackground" Value="Transparent" />
+      <Setter Property="HeadersVisibility" Value="Column" />
+      <Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
+      <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
+      <Setter Property="SelectionMode" Value="Extended" />
+      <Setter Property="GridLinesVisibility" Value="None" />
+      <Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource DataGridGridLinesBrush}" />
+      <Setter Property="VerticalGridLinesBrush" Value="{DynamicResource DataGridGridLinesBrush}" />
+      <Setter Property="DropLocationIndicatorTemplate">
+        <Template>
+          <Rectangle Fill="{DynamicResource DataGridDropLocationIndicatorBackground}"
+                     Width="2" />
+        </Template>
+      </Setter>
+      <Setter Property="Template">
+        <ControlTemplate>
+          <Border x:Name="DataGridBorder"
+                  Background="{TemplateBinding Background}"
+                  BorderBrush="{TemplateBinding BorderBrush}"
+                  BorderThickness="{TemplateBinding BorderThickness}"
+                  CornerRadius="{TemplateBinding CornerRadius}">
+            <Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="Auto,*,Auto,Auto">
+              <DataGridColumnHeader Name="PART_TopLeftCornerHeader"
+                                    Theme="{StaticResource DataGridTopLeftColumnHeader}" />
+              <DataGridColumnHeadersPresenter Name="PART_ColumnHeadersPresenter"
+                                              Grid.Column="1"
+                                              Grid.Row="0" Grid.ColumnSpan="2" />
+              <Rectangle Name="PART_ColumnHeadersAndRowsSeparator"
+                         Grid.Row="0" Grid.ColumnSpan="3" Grid.Column="0"
+                         VerticalAlignment="Bottom"
+                         Height="1"
+                         Fill="{DynamicResource DataGridGridLinesBrush}" />
+
+              <DataGridRowsPresenter Name="PART_RowsPresenter"
+                                     Grid.Row="1"
+                                     Grid.RowSpan="2"
+                                     Grid.ColumnSpan="3" Grid.Column="0">
+                <DataGridRowsPresenter.GestureRecognizers>
+                  <ScrollGestureRecognizer CanHorizontallyScroll="True" CanVerticallyScroll="True" />
+                </DataGridRowsPresenter.GestureRecognizers>
+              </DataGridRowsPresenter>
+              <Rectangle Name="PART_BottomRightCorner"
+                         Fill="{DynamicResource DataGridScrollBarsSeparatorBackground}"
+                         Grid.Column="2"
+                         Grid.Row="2" />
+              <ScrollBar Name="PART_VerticalScrollbar"
+                         Orientation="Vertical"
+                         Grid.Column="2"
+                         Grid.Row="1"
+                         Width="{DynamicResource ScrollBarSize}" />
+
+              <Grid Grid.Column="1"
+                    Grid.Row="2"
+                    ColumnDefinitions="Auto,*">
+                <Rectangle Name="PART_FrozenColumnScrollBarSpacer" />
+                <ScrollBar Name="PART_HorizontalScrollbar"
+                           Grid.Column="1"
+                           Orientation="Horizontal"
+                           Height="{DynamicResource ScrollBarSize}" />
+              </Grid>
+              <Border x:Name="PART_DisabledVisualElement"
+                      Grid.ColumnSpan="3" Grid.Column="0"
+                      Grid.Row="0" Grid.RowSpan="4"
+                      IsHitTestVisible="False"
+                      HorizontalAlignment="Stretch"
+                      VerticalAlignment="Stretch"
+                      CornerRadius="2"
+                      Background="{DynamicResource DataGridDisabledVisualElementBackground}"
+                      IsVisible="{Binding !$parent[DataGrid].IsEnabled}" />
             </Grid>
           </Border>
-          <Rectangle x:Name="HorizontalSeparator"
-                     Grid.Row="2"
-                     Grid.ColumnSpan="2"
-                     Height="1"
-                     Margin="1,0,1,0"
-                     HorizontalAlignment="Stretch"
-                     Fill="{TemplateBinding SeparatorBrush}"
-                     IsVisible="{TemplateBinding AreSeparatorsVisible}" />
-
-          <ContentPresenter Grid.RowSpan="2"
-                            Grid.Column="1"
-                            HorizontalAlignment="Center"
-                            VerticalAlignment="Center"
-                            Content="{TemplateBinding Content}" />
-        </Grid>
-      </ControlTemplate>
-    </Setter>
-  </Style>
-
-  <Style Selector="DataGridRowHeader /template/ Rectangle#RowInvalidVisualElement">
-    <Setter Property="Opacity" Value="0" />
-  </Style>
-  <Style Selector="DataGridRowHeader:invalid /template/ Rectangle#RowInvalidVisualElement">
-    <Setter Property="Opacity" Value="0.4" />
-  </Style>
-  <Style Selector="DataGridRowHeader:invalid /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Opacity" Value="0" />
-  </Style>
-
-  <Style Selector="DataGridRowHeader /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowBackgroundBrush}" />
-  </Style>
-  <Style Selector="DataGridRow:pointerover DataGridRowHeader /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowHoveredBackgroundColor}" />
-  </Style>
-  <Style Selector="DataGridRowHeader:selected /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundBrush}" />
-    <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedUnfocusedBackgroundOpacity}" />
-  </Style>
-  <Style Selector="DataGridRow:pointerover DataGridRowHeader:selected /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundBrush}" />
-    <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedHoveredUnfocusedBackgroundOpacity}" />
-  </Style>
-  <Style Selector="DataGridRowHeader:selected:focus /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedBackgroundBrush}" />
-    <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedBackgroundOpacity}" />
-  </Style>
-  <Style Selector="DataGridRow:pointerover DataGridRowHeader:selected:focus /template/ Rectangle#BackgroundRectangle">
-    <Setter Property="Fill" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundBrush}" />
-    <Setter Property="Opacity" Value="{DynamicResource DataGridRowSelectedHoveredBackgroundOpacity}" />
-  </Style>
-
-  <Style Selector="DataGridRowGroupHeader">
-    <Setter Property="Focusable" Value="False" />
-    <Setter Property="Foreground" Value="{DynamicResource DataGridRowGroupHeaderForegroundBrush}" />
-    <Setter Property="Background" Value="{DynamicResource DataGridRowGroupHeaderBackgroundBrush}" />
-    <Setter Property="FontSize" Value="15" />
-    <Setter Property="MinHeight" Value="32" />
-    <Setter Property="Template">
-      <ControlTemplate>
-        <DataGridFrozenGrid Name="PART_Root"
-                            MinHeight="{TemplateBinding MinHeight}"
-                            ColumnDefinitions="Auto,Auto,Auto,Auto,*"
-                            RowDefinitions="*,Auto">
-
-          <Rectangle Name="IndentSpacer"
-                     Grid.Column="1" />
-          <ToggleButton Name="ExpanderButton"
-                        Grid.Column="2"
-                        Width="12"
-                        Height="12"
-                        Margin="12,0,0,0"
-                        BorderBrush="{TemplateBinding BorderBrush}"
-                        BorderThickness="{TemplateBinding BorderThickness}"
-                        Background="{TemplateBinding Background}"
-                        CornerRadius="{TemplateBinding CornerRadius}"
-                        Focusable="False"
-                        Foreground="{TemplateBinding Foreground}" />
-
-          <StackPanel Grid.Column="3"
-                      Orientation="Horizontal"
-                      VerticalAlignment="Center"
-                      Margin="12,0,0,0">
-            <TextBlock Name="PropertyNameElement"
-                       Margin="4,0,0,0"
-                       IsVisible="{TemplateBinding IsPropertyNameVisible}"
-                       Foreground="{TemplateBinding Foreground}" />
-            <TextBlock Margin="4,0,0,0"
-                       Text="{Binding Key}"
-                       Foreground="{TemplateBinding Foreground}" />
-            <TextBlock Name="ItemCountElement"
-                       Margin="4,0,0,0"
-                       IsVisible="{TemplateBinding IsItemCountVisible}"
-                       Foreground="{TemplateBinding Foreground}" />
-          </StackPanel>
-
-          <Rectangle x:Name="CurrencyVisual"
-                     Grid.ColumnSpan="5"
-                     HorizontalAlignment="Stretch"
-                     VerticalAlignment="Stretch"
-                     Fill="Transparent"
-                     IsHitTestVisible="False"
-                     Stroke="{DynamicResource DataGridCurrencyVisualPrimaryBrush}"
-                     StrokeThickness="1" />
-          <Grid x:Name="FocusVisual"
-                Grid.ColumnSpan="5"
-                IsHitTestVisible="False">
-            <Rectangle HorizontalAlignment="Stretch"
-                       VerticalAlignment="Stretch"
-                       Fill="Transparent"
-                       IsHitTestVisible="False"
-                       Stroke="{DynamicResource DataGridCellFocusVisualPrimaryBrush}"
-                       StrokeThickness="2" />
-            <Rectangle Margin="2"
-                       HorizontalAlignment="Stretch"
-                       VerticalAlignment="Stretch"
-                       Fill="Transparent"
-                       IsHitTestVisible="False"
-                       Stroke="{DynamicResource DataGridCellFocusVisualSecondaryBrush}"
-                       StrokeThickness="1" />
-          </Grid>
-
-          <DataGridRowHeader Name="PART_RowHeader"
-                             Grid.RowSpan="2"
-                             DataGridFrozenGrid.IsFrozen="True" />
-
-          <Rectangle x:Name="PART_BottomGridLine"
-                     Grid.Row="1"
-                     Grid.ColumnSpan="5"
-                     Height="1" />
-        </DataGridFrozenGrid>
-      </ControlTemplate>
-    </Setter>
-  </Style>
-
-  <Style Selector="DataGridRowGroupHeader /template/ ToggleButton#ExpanderButton">
-    <Setter Property="Template">
-      <ControlTemplate>
-        <Border Grid.Column="0"
-                Width="12"
-                Height="12"
-                Background="Transparent"
-                HorizontalAlignment="Center"
-                VerticalAlignment="Center">
-          <Path Fill="{TemplateBinding Foreground}"
-                HorizontalAlignment="Right"
-                VerticalAlignment="Center"
-                Stretch="Uniform" />
-        </Border>
-      </ControlTemplate>
-    </Setter>
-  </Style>
-
-  <Style Selector="DataGridRowGroupHeader /template/ ToggleButton#ExpanderButton /template/ Path">
-    <Setter Property="Data" Value="{StaticResource DataGridRowGroupHeaderIconClosedPath}" />
-    <Setter Property="Stretch" Value="Uniform" />
-  </Style>
-
-  <Style Selector="DataGridRowGroupHeader /template/ ToggleButton#ExpanderButton:checked /template/ Path">
-    <Setter Property="Data" Value="{StaticResource DataGridRowGroupHeaderIconOpenedPath}" />
-    <Setter Property="Stretch" Value="UniformToFill" />
-  </Style>
-
-  <Style Selector="DataGridRowGroupHeader /template/ DataGridFrozenGrid#PART_Root">
-    <Setter Property="Background" Value="{Binding $parent[DataGridRowGroupHeader].Background}" />
-  </Style>
-  <Style Selector="DataGridRowGroupHeader:pointerover /template/ DataGridFrozenGrid#PART_Root">
-    <Setter Property="Background" Value="{DynamicResource DataGridRowGroupHeaderHoveredBackgroundBrush}" />
-  </Style>
-  <Style Selector="DataGridRowGroupHeader:pressed /template/ DataGridFrozenGrid#PART_Root">
-    <Setter Property="Background" Value="{DynamicResource DataGridRowGroupHeaderPressedBackgroundBrush}" />
-  </Style>
-
-  <Style Selector="DataGridRowGroupHeader /template/ Rectangle#CurrencyVisual">
-    <Setter Property="IsVisible" Value="False" />
-  </Style>
-  <Style Selector="DataGridRowGroupHeader /template/ Grid#FocusVisual">
-    <Setter Property="IsVisible" Value="False" />
-  </Style>
-  <Style Selector="DataGridRowGroupHeader:current /template/ Rectangle#CurrencyVisual">
-    <Setter Property="IsVisible" Value="True" />
-  </Style>
-  <Style Selector="DataGrid:focus DataGridRowGroupHeader:current /template/ Grid#FocusVisual">
-    <Setter Property="IsVisible" Value="True" />
-  </Style>
-
-  <Style Selector="DataGrid">
-    <Setter Property="RowBackground" Value="Transparent" />
-    <Setter Property="AlternatingRowBackground" Value="Transparent" />
-    <Setter Property="HeadersVisibility" Value="Column" />
-    <Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
-    <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
-    <Setter Property="SelectionMode" Value="Extended" />
-    <Setter Property="GridLinesVisibility" Value="None" />
-    <Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource DataGridGridLinesBrush}" />
-    <Setter Property="VerticalGridLinesBrush" Value="{DynamicResource DataGridGridLinesBrush}" />
-    <Setter Property="DropLocationIndicatorTemplate">
-      <Template>
-        <Rectangle Fill="{DynamicResource DataGridDropLocationIndicatorBackground}"
-                   Width="2" />
-      </Template>
-    </Setter>
-    <Setter Property="Template">
-      <ControlTemplate>
-        <Border x:Name="DataGridBorder"
-                Background="{TemplateBinding Background}"
-                BorderBrush="{TemplateBinding BorderBrush}"
-                BorderThickness="{TemplateBinding BorderThickness}"
-                CornerRadius="{TemplateBinding CornerRadius}">
-          <Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="Auto,*,Auto,Auto">
-            <Grid.Resources>
-              <ControlTemplate x:Key="TopLeftHeaderTemplate"
-                               TargetType="DataGridColumnHeader">
-                <Grid x:Name="TopLeftHeaderRoot"
-                      RowDefinitions="*,*,Auto">
-                  <Border Grid.RowSpan="2"
-                          BorderThickness="0,0,1,0"
-                          BorderBrush="{DynamicResource DataGridGridLinesBrush}" />
-                  <Rectangle Grid.RowSpan="2"
-                             VerticalAlignment="Bottom"
-                             StrokeThickness="1"
-                             Height="1"
-                             Fill="{DynamicResource DataGridGridLinesBrush}" />
-                </Grid>
-              </ControlTemplate>
-              <ControlTemplate x:Key="TopRightHeaderTemplate"
-                               TargetType="DataGridColumnHeader">
-                <Grid x:Name="RootElement" />
-              </ControlTemplate>
-            </Grid.Resources>
-
-            <DataGridColumnHeader Name="PART_TopLeftCornerHeader"
-                                  Template="{StaticResource TopLeftHeaderTemplate}" />
-            <DataGridColumnHeadersPresenter Name="PART_ColumnHeadersPresenter"
-                                            Grid.Column="1"
-                                            Grid.ColumnSpan="2" />
-            <!--<DataGridColumnHeader Name="PART_TopRightCornerHeader"
-                                  Grid.Column="2"
-                                  Template="{StaticResource TopRightHeaderTemplate}" />-->
-            <Rectangle Name="PART_ColumnHeadersAndRowsSeparator"
-                       Grid.ColumnSpan="3"
-                       VerticalAlignment="Bottom"
-                       Height="1"
-                       Fill="{DynamicResource DataGridGridLinesBrush}" />
-
-            <DataGridRowsPresenter Name="PART_RowsPresenter"
-                                   Grid.Row="1"
-                                   Grid.RowSpan="2"
-                                   Grid.ColumnSpan="3">
-              <DataGridRowsPresenter.GestureRecognizers>
-                <ScrollGestureRecognizer CanHorizontallyScroll="True" CanVerticallyScroll="True" />
-              </DataGridRowsPresenter.GestureRecognizers>
-            </DataGridRowsPresenter>
-            <Rectangle Name="PART_BottomRightCorner"
-                       Fill="{DynamicResource DataGridScrollBarsSeparatorBackground}"
-                       Grid.Column="2"
-                       Grid.Row="2" />
-            <!--<Rectangle Name="BottomLeftCorner"
-                       Fill="{DynamicResource DataGridScrollBarsSeparatorBackground}"
-                       Grid.Row="2"
-                       Grid.ColumnSpan="2" />-->
-            <ScrollBar Name="PART_VerticalScrollbar"
-                       Orientation="Vertical"
-                       Grid.Column="2"
-                       Grid.Row="1"
-                       Width="{DynamicResource ScrollBarSize}" />
-
-            <Grid Grid.Column="1"
-                  Grid.Row="2"
-                  ColumnDefinitions="Auto,*">
-              <Rectangle Name="PART_FrozenColumnScrollBarSpacer" />
-              <ScrollBar Name="PART_HorizontalScrollbar"
-                         Grid.Column="1"
-                         Orientation="Horizontal"
-                         Height="{DynamicResource ScrollBarSize}" />
-            </Grid>
-            <Border x:Name="PART_DisabledVisualElement"
-                    Grid.ColumnSpan="3"
-                    Grid.RowSpan="4"
-                    IsHitTestVisible="False"
-                    HorizontalAlignment="Stretch"
-                    VerticalAlignment="Stretch"
-                    CornerRadius="2"
-                    Background="{DynamicResource DataGridDisabledVisualElementBackground}"
-                    IsVisible="{Binding !$parent[DataGrid].IsEnabled}" />
-          </Grid>
-        </Border>
-      </ControlTemplate>
-    </Setter>
-  </Style>
-
-  <Style Selector="DataGrid:empty-columns /template/ DataGridColumnHeader#PART_TopLeftCornerHeader">
-    <Setter Property="IsVisible" Value="False" />
-  </Style>
-  <Style Selector="DataGrid:empty-columns /template/ DataGridColumnHeadersPresenter#PART_ColumnHeadersPresenter">
-    <Setter Property="IsVisible" Value="False" />
-  </Style>
-  <Style Selector="DataGrid:empty-columns /template/ Rectangle#PART_ColumnHeadersAndRowsSeparator">
-    <Setter Property="IsVisible" Value="False" />
-  </Style>
+        </ControlTemplate>
+      </Setter>
+
+      <Style Selector="^:empty-columns">
+        <Style Selector="^ /template/ DataGridColumnHeader#PART_TopLeftCornerHeader">
+          <Setter Property="IsVisible" Value="False" />
+        </Style>
+        <Style Selector="^ /template/ DataGridColumnHeadersPresenter#PART_ColumnHeadersPresenter">
+          <Setter Property="IsVisible" Value="False" />
+        </Style>
+        <Style Selector="^ /template/ Rectangle#PART_ColumnHeadersAndRowsSeparator">
+          <Setter Property="IsVisible" Value="False" />
+        </Style>
+      </Style>
+    </ControlTheme>
+  </Styles.Resources>
 </Styles>