wpf icon indicating copy to clipboard operation
wpf copied to clipboard

Red border doesn't disappear with INotifyDataErrorInfo

Open vsfeedback opened this issue 1 year ago • 2 comments

This issue has been moved from a ticket on Developer Community.


I have attached a simple project reproducing the issue.

The issue is that the red border (meaning there is an error) remains on my control even though error is cleared.

In a WPF app, I have a “MainWindow”, containing a “TestContainer” view (using a ContentControl), containing a “TestUserControl” view.

In the TestUserControlViewModel, when the OutsideString dependency property is set, I clear the error manually. But this is not taken into account and the red border remains --> NOK

If I add a button to the UI to clear the error, then it works and the red border disappears.

It looks like a bug in the framework.

Do you have any idea ?

WpfApp1.zip


Original Comments

Feedback Bot on 3/19/2024, 07:17 PM:

(private comment, text removed)

Ann Yang [MSFT] on 3/20/2024, 00:28 AM:

(private comment, text removed)

Nicolas Géré on 3/20/2024, 03:02 AM:

(private comment, text removed)

Feedback Bot on 3/26/2024, 01:43 AM:

(private comment, text removed)


Original Solutions

(no solutions)

vsfeedback avatar Mar 28 '24 03:03 vsfeedback

It seems that the reason it is not cleared is that there is no longer any error to clear, i.e. while on load the red border is shown, it doesn't reflect the current validation state.

So if there is a bug, it's in the red border being visible from the beginning, not that it doesn't disappear on error clearance.

miloush avatar Mar 28 '24 15:03 miloush

OK I am convinced this is a bug.

https://github.com/dotnet/wpf/blob/ee1e9e41c53857653047db7d277960de5a06560b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Validation.cs#L453-L457

  1. code above schedules an operation to show the adorner, because adorner layer does not exist yet
  2. then the adorner is to be hidden, at that point layer already exists but dispatcher did not get to run the show operation yet
  3. the dispatcher runs and shows the adorner although that is an outdated instruction

The solution is to:

  1. either remember the requested visibility and recheck it inside the dispatcher operation
  2. or, remember the dispatcher operation and cancel it if outdated

It is slightly complicated by the fact that the above is all static methods and both solutions need to be stored per target instance.

miloush avatar Mar 28 '24 15:03 miloush