c# - Custom Validation is only run once -


i creating mvvm silverlight application , trying add validation model.

in particular instance have multiple phone number boxes , have requirement @ least 1 phone number must entered. facilitate have properties (homephone, workphone, mobilephone , otherphone) on model decorated customvalidation attribute.

example property:

    private string _otherphone;     [customvalidation(typeof(mymodel), "validatephonenumbers")]     public string otherphone     {         { return _otherphone; }         set         {             if (_otherphone == value) return;             _otherphone = value;             validator.validateproperty(value, new validationcontext(this, null, null) { membername = "otherphone" });             raisepropertychanged(() => homephone);             raisepropertychanged(() => workphone);             raisepropertychanged(() => mobilephone);             raisepropertychanged(() => otherphone);         }     } 

along custom validator itself:

    public static validationresult validatephonenumbers(string number, validationcontext validationcontext)     {         mymodel mymodel = (mymodel)validationcontext.objectinstance;         return string.isnullorempty(mymodel.homephone) && string.isnullorempty(mymodel.workphone) && string.isnullorempty(mymodel.mobilephone) && string.isnullorempty(mymodel.otherphone)                    ? new validationresult("at least 1 phone number must entered")                    : validationresult.success;     } 

i have ensured backing store set in property setter before validation run, ensure validatephonenumbers method able check latest value.

when try save model, executing updatebindingexpression on bindings in view. works correctly first time try save, , 4 fields highlighted having error.

if try save again however, fields marked passed validation, , breakpoint in validatephonenumbers never hit. why this?

thanks

i'm sure every time spend long enough fighting bug resort posting on so, work out actual answer 20 seconds later... if (_otherphone == value) return; causing validation not run - optimisation make sense if validation wasn't dependent on property.

never mind...


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -