wpf - When to call the IDataErrorInfo's AddError method -


i have viewmodel class implements idataerrorinfo interface.

in each property's set validate value passed in , if fails validation call method called adderror add error property. adderror method adds item underlying data type i'm using manage errors (a dictionary(of string, list(of string))).

currently things working during data entry. if user enters invalid values property, frameworkelement used input data highlighted tooltip set error message.

now, here's problem.

say object contains invalid fields start.... example, if have person class required field "name" , create new instance of person class. name field not highlighted "error" because name property's set method hasn't been called yet.

so, put validation property's get well.

this seems works but......it feels hack. , property validation has done model (as opposed viewmodel i'm working with). model bubbles appropriate error message should set can't error message unless set model's property.

any advise on best approach implementing idataerrorinfo interface really appreciated.

thanks!

-frinny

i figured out doesn't feel hack.

i should have mentioned have base class viewmodel inherit from. in base class implementing idataerrorinfo interface.

what ended doing adding new mustoverride method base viewmodel class called "validate" validates property name supplied it. if validation fails adds entry underlying errors dictionary.

i call validate method in item property (that implements idataerrorinfo.item property).

this way each derived class can contain it's own validation code , can sure method exists because it's part of base viewmodel class.

if isn't best approach, please let me know.

-frinny


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -