Gavin Osborn
Gavin Osborn

Reputation: 2603

ValidationSummary to show non-form validation

I am writing a Silverlight screen that takes user input from a file, parses the file and displays any validation errors onto the screen. The data from the file is never displayed, the purpose of the screen is purely for validation feedback.

I decided to create a ViewModel that implements INotifyDataErrorInfo and in my view I would use the ValidationSummary control to display those errors.

My thinking in doing this was that the ValidationSummary control would listen to the INotifyDataErrorInfo.ErrorsChanged event on my ViewModel and would update itself accordingly as the state of the ViewModel changes.

Unfortunately it isn't working.

If I add a TextBox to my View and bind it to a property on my ViewModel... any validation errors that occur as a result of changing the value in the TextBox do appear in the summary - which confirms nicely that I have implemented INotifyDataErrorInfo correctly.

Does the ValidationSummary control really depend on UI interaction/Binding for it to display errors?

Is the assumption that it should listen to any messages from INotifyDataErrorInfo regardless of how the UI is composed correct?

Thanks in advance for your help.

Upvotes: 1

Views: 1644

Answers (2)

katit
katit

Reputation: 17915

ValidationSummary control needs to be in a same container as controls that being validated in order to display errors. I didn't succeed at displaying entity-level validations and didn't find much information on this topic.

As I understand - you need to create your own validation summary control that listens to event and binds to error source.

Upvotes: 1

Anatolii Gabuza
Anatolii Gabuza

Reputation: 6260

I think the purpose of using INotifyDataErrorInfo for such reasons is incorrect. Here what MSDN say:

Defines members that data entity classes can implement to provide custom synchronous and asynchronous validation support. INotifyDataErrorInfo Interface

And now the question is: do we need to implement this interface? I assume that for informing user about result of importing or exporting data, using MVVM pattern and INotifyPropertyChanged will be more than enough.

Upvotes: 0

Related Questions