.net - Add Custom Validation Errors in Silverlight -
is there way add custom validation errors list of control's errors? know how use idataerrorinfo, inotifyerrorinfo, validationattribute, etc, add custom validation errors code.
found way:
first, create public class holding our error message:
public class tagmodelerror { private readonly string errormessage;
public tagmodelerror(string errormessage) { this.errormessage = errormessage; } public object tag { { return new object(); } set { throw new validationexception(this.errormessage); } } }next, create helper method:
public static void addvalidationerror(this control control, string errormessage) { var expression = elm.getbindingexpression(frameworkelement.tagproperty);
if (expression == null) { expression = control.setbinding(frameworkelement.tagproperty, new binding("tag") { mode = bindingmode.twoway, validatesonexceptions = true, updatesourcetrigger = updatesourcetrigger.explicit, source = new tagmodelerror(errormessage) }) bindingexpression; } expression.updatesource(); }
i using tag property because seldom required, can use one. trick here cause exception when writing model.
Comments
Post a Comment