From ed582a9fde3aef0a2cd9462cbe66c9dc1446076d Mon Sep 17 00:00:00 2001 From: aldelaro5 Date: Wed, 3 Aug 2022 22:39:40 -0400 Subject: [PATCH] Implement DataContext update notifications on the DataGrid This fixes #5661 by allowing the DataGrid to notify its cells that their DataContext is about to be changed. --- src/Avalonia.Controls.DataGrid/DataGrid.cs | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Avalonia.Controls.DataGrid/DataGrid.cs b/src/Avalonia.Controls.DataGrid/DataGrid.cs index d42468f47e..f4cd425c53 100644 --- a/src/Avalonia.Controls.DataGrid/DataGrid.cs +++ b/src/Avalonia.Controls.DataGrid/DataGrid.cs @@ -2167,6 +2167,38 @@ namespace Avalonia.Controls return desiredSize; } + + /// + protected override void OnDataContextBeginUpdate() + { + base.OnDataContextBeginUpdate(); + foreach (DataGridRow row in GetAllRows()) + { + foreach (DataGridCell cell in row.Cells) + { + if (cell.Content is StyledElement) + { + DataContextProperty.Notifying?.Invoke((IAvaloniaObject)cell.Content, true); + } + } + } + } + + /// + protected override void OnDataContextEndUpdate() + { + base.OnDataContextEndUpdate(); + foreach (DataGridRow row in GetAllRows()) + { + foreach (DataGridCell cell in row.Cells) + { + if (cell.Content is StyledElement) + { + DataContextProperty.Notifying?.Invoke((IAvaloniaObject)cell.Content, false); + } + } + } + } /// /// Raises the BeginningEdit event.