I’m doing an app using Prism 4 and WPF and I’ve some inputs validations and it works as expected but when the user clicks a button I need to know in that moment whether there are validation errors presents.
Does Prism4 have something implemented to handle this or I’ve to implement it by hand?
Dealing with validation errors isn’t something Prism provides as a part of the library. What prism does provide that can be useful when implementing validation is the
IConfirmNavigationRequestinterface, which enables you to stop navigation in certain cases – for example when the page did not pass validation.To implement validation in your application, I recommend using the
IDataErrorInfointerface (orINotifyDataErrorInfoin .NET 4.5/Silverlight).EDIT
To know whether your view passed validation, you’ll need to expose an
IsValidproperty in your viewmodel that will return this information. One way to do so is to examine the viewmodel and return this data; another way is to have yourViewBaseregister to its errors event usingValidation.AddErrorHandler, and callViewModelBase.AddError()/ViewModelBase.RemoveError()on your view-model. This way your view-model knows about the validation errors and can easily return whether the view is valid or not.