diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml b/samples/ControlCatalog/Pages/DataGridPage.xaml
index 31b4039d33..27272a9ff7 100644
--- a/samples/ControlCatalog/Pages/DataGridPage.xaml
+++ b/samples/ControlCatalog/Pages/DataGridPage.xaml
@@ -10,11 +10,11 @@
+
+
+
-
@@ -54,7 +54,8 @@
-
diff --git a/src/Avalonia.Controls.DataGrid/DataGridCell.cs b/src/Avalonia.Controls.DataGrid/DataGridCell.cs
index f9685b3682..dd802678d4 100644
--- a/src/Avalonia.Controls.DataGrid/DataGridCell.cs
+++ b/src/Avalonia.Controls.DataGrid/DataGridCell.cs
@@ -14,7 +14,7 @@ namespace Avalonia.Controls
/// Represents an individual cell.
///
[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);
}
}
diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs
index e57d6bbde2..fbdb979e24 100644
--- a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs
+++ b/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();
///
@@ -399,6 +401,24 @@ namespace Avalonia.Controls
}
}
}
+
+ ///
+ /// Backing field for CellTheme property.
+ ///
+ public static readonly DirectProperty CellThemeProperty =
+ AvaloniaProperty.RegisterDirect(
+ nameof(CellTheme),
+ o => o.CellTheme,
+ (o, v) => o.CellTheme = v);
+
+ ///
+ /// Gets or sets the cell theme.
+ ///
+ public ControlTheme CellTheme
+ {
+ get { return _cellTheme; }
+ set { SetAndRaise(CellThemeProperty, ref _cellTheme, value); }
+ }
///
/// Backing field for Header property
diff --git a/src/Avalonia.Controls.DataGrid/DataGridRowGroupHeader.cs b/src/Avalonia.Controls.DataGrid/DataGridRowGroupHeader.cs
index 9f37e8a6aa..d63c738133 100644
--- a/src/Avalonia.Controls.DataGrid/DataGridRowGroupHeader.cs
+++ b/src/Avalonia.Controls.DataGrid/DataGridRowGroupHeader.cs
@@ -113,7 +113,6 @@ namespace Avalonia.Controls
///
public DataGridRowGroupHeader()
{
- //DefaultStyleKey = typeof(DataGridRowGroupHeader);
AddHandler(InputElement.PointerPressedEvent, (s, e) => DataGridRowGroupHeader_PointerPressed(e), handledEventsToo: true);
}
diff --git a/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs
index bb8637cda2..79247aa87f 100644
--- a/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs
+++ b/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
///
public class DataGridTextColumn : DataGridBoundColumn
{
+ private readonly Lazy _cellTextBoxTheme;
+ private readonly Lazy _cellTextBlockTheme;
+
///
/// Initializes a new instance of the class.
///
public DataGridTextColumn()
{
BindingTarget = TextBox.TextProperty;
+
+ _cellTextBoxTheme = new Lazy(() =>
+ OwningGrid.TryFindResource("DataGridCellTextBoxTheme", out var theme) ? (ControlTheme)theme : null);
+ _cellTextBlockTheme = new Lazy(() =>
+ OwningGrid.TryFindResource("DataGridCellTextBlockTheme", out var theme) ? (ControlTheme)theme : null);
}
///
@@ -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;
}
-
+
///
/// Gets a read-only element that is bound to the column's property value.
///
@@ -174,10 +186,14 @@ namespace Avalonia.Controls
/// A new, read-only element that is bound to the column's property value.
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)
diff --git a/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml b/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml
index fb032fec3e..a80cc2173c 100644
--- a/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml
+++ b/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml
@@ -1,8 +1,8 @@
-
+
0.6
0.8
- 12,0,12,0
M1875 1011l-787 787v-1798h-128v1798l-787 -787l-90 90l941 941l941 -941z
M1965 947l-941 -941l-941 941l90 90l787 -787v1798h128v-1798l787 787z
@@ -13,10 +13,12 @@
-
+
-
+
@@ -27,14 +29,12 @@
-
+
-
-
-
-
+
@@ -44,157 +44,425 @@
Opacity="0.4"
Color="{DynamicResource SystemBaseMediumLowColor}" />
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Fill="{TemplateBinding SeparatorBrush}"
+ IsVisible="{TemplateBinding AreSeparatorsVisible}" />
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+