From 94267b0ac84a6aaa52067f3a2a9699e3dc2ef6c5 Mon Sep 17 00:00:00 2001 From: tom-englert Date: Fri, 22 Aug 2025 09:26:42 +0200 Subject: [PATCH] Fix #5428: DataGrid with template columns causes crash when scrolling --- .../Windows/Automation/Peers/ItemsControlAutomationPeer.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs index a5b49ae2502..4dad9a63153 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/ItemsControlAutomationPeer.cs @@ -162,6 +162,12 @@ protected override List GetChildrenCore() dataItem = item; } + if (dataItem == null) + { + // skip null items + continue; + } + // try to reuse old peer if it exists either in Current AT or in WeakRefStorage of Peers being sent to Client ItemAutomationPeer peer = oldChildren[dataItem]; peer = ReusePeerForItem(peer, dataItem);