From 3378201230dfcc846859426c31834ec26252ef51 Mon Sep 17 00:00:00 2001 From: Maruhl Date: Sat, 13 Aug 2022 10:30:30 +0200 Subject: [PATCH] Code refactored for better maintainability (Code from #8668) --- src/Avalonia.Controls.DataGrid/DataGrid.cs | 40 ++++++++++------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGrid.cs b/src/Avalonia.Controls.DataGrid/DataGrid.cs index f4cd425c53..cacd5c5a16 100644 --- a/src/Avalonia.Controls.DataGrid/DataGrid.cs +++ b/src/Avalonia.Controls.DataGrid/DataGrid.cs @@ -2172,34 +2172,18 @@ namespace Avalonia.Controls 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); - } - } - } + + NotifyDataContextPropertyForAllRowCells(GetAllRows(), 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); - } - } - } - } + NotifyDataContextPropertyForAllRowCells(GetAllRows(), false); + } + /// /// Raises the BeginningEdit event. /// @@ -3197,6 +3181,20 @@ namespace Avalonia.Controls } } + private static void NotifyDataContextPropertyForAllRowCells(IEnumerable rowSource, bool arg2) + { + foreach (DataGridRow row in rowSource) + { + foreach (DataGridCell cell in row.Cells) + { + if (cell.Content is StyledElement cellContent) + { + DataContextProperty.Notifying?.Invoke(cellContent, arg2); + } + } + } + } + private void UpdateRowDetailsVisibilityMode(DataGridRowDetailsVisibilityMode newDetailsMode) { int itemCount = DataConnection.Count;