From 22ef68e43960f57368c593ca31841fe90c9f4f3a Mon Sep 17 00:00:00 2001 From: Gundlack Florian Date: Thu, 13 Jul 2023 13:45:16 +0200 Subject: [PATCH 1/2] Fixed issue where RowDetailsTemplate was getting the wrong DataContext --- src/Avalonia.Controls.DataGrid/DataGridRows.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGridRows.cs b/src/Avalonia.Controls.DataGrid/DataGridRows.cs index 44079d24d0..107a2a7353 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridRows.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridRows.cs @@ -2970,10 +2970,7 @@ namespace Avalonia.Controls if (detailsContent != null) { _rowsPresenter.Children.Add(detailsContent); - if (dataItem != null) - { - detailsContent.DataContext = dataItem; - } + detailsContent.DataContext = dataItem; detailsContent.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); RowDetailsHeightEstimate = detailsContent.DesiredSize.Height; _rowsPresenter.Children.Remove(detailsContent); From 3fc0d19ad017a819535a0610058652aa07d57348 Mon Sep 17 00:00:00 2001 From: Gundlack Florian Date: Thu, 13 Jul 2023 15:47:28 +0200 Subject: [PATCH 2/2] Moved detailsContent.DataContext assignation before Children.Add --- src/Avalonia.Controls.DataGrid/DataGridRows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGridRows.cs b/src/Avalonia.Controls.DataGrid/DataGridRows.cs index 107a2a7353..c9a348d172 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridRows.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridRows.cs @@ -2969,8 +2969,8 @@ namespace Avalonia.Controls var detailsContent = RowDetailsTemplate.Build(dataItem); if (detailsContent != null) { - _rowsPresenter.Children.Add(detailsContent); detailsContent.DataContext = dataItem; + _rowsPresenter.Children.Add(detailsContent); detailsContent.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); RowDetailsHeightEstimate = detailsContent.DesiredSize.Height; _rowsPresenter.Children.Remove(detailsContent);