Jul 16, 2012 at 7:59 PM
Edited Jul 16, 2012 at 7:59 PM
I have a Customer ViewModel in which I would like to validate the uniqueness of the Code property when saving the view model.
I want to show the error in the InfoBarMessageControl just like the field validations already are (which are attribute based and present in the model class).
In my view I have bound the properties to the viewmodel using UpdateSourceTrigger=PropertyChanged.
When I show my view(model) the fields are nicely shown in the InfoBarMessageControl as required. So far so good.
Now I thought I had to add the business rule validation 'check for unique code' in the overriden method ValidateBusinessRules of the viewmodel.
However, when I set a breakpoint in ValidateBusinessRules I see it gets called every time a property in the view changes. I don not want that behaviour because the database call is relative expensive.
How can I delay the call to ValidateBusinessRules so that it occurs only when the OK button of the datawindow is pressed e.g. the viewmode is saved?
And if this is not possible how can I make sure that if I put the validation in the overridden Save method, the error message is stil displayed in InfoBarMessageControl? Is there a possibility to manually add an error to the ValidationResults so it will
be displayed in the InforBarMessageControl?