From 0f4ffd7b9103e1cff037ae0ad020995f99c578a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20=C5=A0olt=C3=A9s?= Date: Wed, 11 Aug 2021 21:03:20 +0200 Subject: [PATCH] Add Content property --- src/TemplatedDataGrid/DataGridCell.cs | 11 +++++++++++ src/TemplatedDataGrid/DataGridRow.cs | 1 + src/TemplatedDataGrid/Themes/Fluent.axaml | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/TemplatedDataGrid/DataGridCell.cs b/src/TemplatedDataGrid/DataGridCell.cs index 9e1b25c..fdf4538 100644 --- a/src/TemplatedDataGrid/DataGridCell.cs +++ b/src/TemplatedDataGrid/DataGridCell.cs @@ -7,6 +7,9 @@ namespace TemplatedDataGrid { public class DataGridCell : TemplatedControl { + public static readonly StyledProperty ContentProperty = + AvaloniaProperty.Register(nameof(Content)); + public static readonly StyledProperty CellTemplateProperty = AvaloniaProperty.Register(nameof(CellTemplate)); @@ -16,5 +19,13 @@ namespace TemplatedDataGrid get => GetValue(CellTemplateProperty); set => SetValue(CellTemplateProperty, value); } + + [Content] + [DependsOn(nameof(CellTemplate))] + public object? Content + { + get { return GetValue(ContentProperty); } + set { SetValue(ContentProperty, value); } + } } } diff --git a/src/TemplatedDataGrid/DataGridRow.cs b/src/TemplatedDataGrid/DataGridRow.cs index a69b270..e108a5b 100644 --- a/src/TemplatedDataGrid/DataGridRow.cs +++ b/src/TemplatedDataGrid/DataGridRow.cs @@ -74,6 +74,7 @@ namespace TemplatedDataGrid var cell = new DataGridCell() { [Grid.ColumnProperty] = columnDefinitions.Count - 1, + [!DataGridCell.ContentProperty] = this[!DataGridRow.DataContextProperty], [!DataGridCell.CellTemplateProperty] = templateColumn[!DataGridTemplateColumn.CellTemplateProperty] }; _rootChildren.Add(cell); diff --git a/src/TemplatedDataGrid/Themes/Fluent.axaml b/src/TemplatedDataGrid/Themes/Fluent.axaml index a2e09b3..f774c82 100644 --- a/src/TemplatedDataGrid/Themes/Fluent.axaml +++ b/src/TemplatedDataGrid/Themes/Fluent.axaml @@ -71,7 +71,7 @@