1

The documentation I've found for WPF's INotifyDataErrorInfo seems to state that the GetErrors() method is called when either a value is set through the UI, or as a result of the INotifyDataErrorInfo's ErrorsChanged event having been called.

But that doesn't match what I'm seeing when debugging a window whose DataContext is a viewmodel that implements INotifyDataErrorInfo (the viewmodel in question is built on Mvvm Light).

Instead, GetErrors() is called when the window is initialized and its DataContext is set, but afterwards only when the viewmodel code raises the ErrorsChanged event. Which in my case it does whenever certain properties are set in the viewmodel, by code I've written to raise the ErrorsChanged event.

I'm asking this question because I want to know if I need to handle the situation where GetErrors() might get called by WPF without me first having called the validation code. That could erroneously report that no errors exist, when in fact that's only the case because validation hasn't taken place yet.

Mark Olbert
  • 6,584
  • 9
  • 35
  • 69
  • You shouldn't need that information. Always react "on demand", not beforehand. Check my answer here https://stackoverflow.com/questions/34665650/force-inotifydataerrorinfo-validation – Simon Mourier Apr 20 '18 at 17:29
  • Thanx, Simon, I had seen your answer, and had experimented with it, For design reasons that it would've been off-topic to describe, the on demand approach isn't a good fit for what I'm doing. But I found your answer very interesting, and upvoted it. – Mark Olbert Apr 20 '18 at 19:02

1 Answers1

1

It's called when errorschanged is raised.

I just experimented with a sample I have. This thing: https://gallery.technet.microsoft.com/scriptcenter/WPF-Entity-Framework-MVVM-78cdc204

I put a break point in the geterrors method of my base class and spun it up.
Geterrors was not called until I made something invalid.
If you see different behaviour then it's something you are doing differently.

Andy
  • 11,864
  • 2
  • 17
  • 20
  • Thanx for checking. Your answer led me to go back and check my code base, and I noticed that I was calling the Validate() method for the viewmodel in certain cases that had nothing to do with a particular property being set. – Mark Olbert Apr 20 '18 at 19:11