From b8ecfd53e79455a283afb6d0b31a63566824d33a Mon Sep 17 00:00:00 2001 From: Akshat Sinha Date: Wed, 15 Oct 2025 22:16:28 +0530 Subject: [PATCH] Fix validation adorner race condition (#8969) Fixes a race condition where the validation adorner (red border) remains visible even after errors are cleared programmatically. This occurred when the adorner layer didn't exist during error occurrence, causing a delayed dispatcher operation to show the adorner using stale state. The fix ensures the current error state is always checked when the dispatcher operation executes, preventing the adorner from being shown for errors that have already been cleared. --- .../System/Windows/Controls/Validation.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Validation.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Validation.cs index e169b64b5aa..a3544f2e3b2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Validation.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Validation.cs @@ -388,7 +388,10 @@ private static object ShowValidationAdornerOperation(object arg) object[] args = (object[])arg; DependencyObject targetElement = (DependencyObject)args[0]; DependencyObject adornerSite = (DependencyObject)args[1]; - bool show = (bool)args[2]; + // bool show = (bool)args[2]; //stale scheduled value + //trying for issue #8969:always use the current error state.. + //no race condition where the adorner is shown for an error that was already cleared + bool show=GetHasError(targetElement); // Check if the element is visible, if not try to show the adorner again once it gets visible. // This is needed because controls hosted in Expander or TabControl don't have a parent/AdornerLayer till the Expander is expanded or the TabItem is selected.