wpf - Validation with IDataErrorInfo through DependencyProperty -
i've created small user control extend fun validation! problem validation not work: idataerrorinfo.this[] never called.
thank in advance help. stephan
here code:
<usercontrol x:class="wpfapplication5.textboxwithvalidation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:name="textboxwithvalidationcontrol"> <grid> <stackpanel orientation="horizontal"> <textbox height="23" width="120" text="{binding path=text,elementname=textboxwithvalidationcontrol, validatesondataerrors=true, updatesourcetrigger=propertychanged}"> </textbox> </stackpanel> </grid>
and code behind is:
public partial class textboxwithvalidation { public static readonly dependencyproperty textproperty = dependencyproperty.register("text", typeof (object), typeof ( textboxwithvalidation ), new frameworkpropertymetadata (default(object), frameworkpropertymetadataoptions .bindstwowaybydefault)); public textboxwithvalidation() { initializecomponent(); } public object text { { return getvalue(textproperty); } set { setvalue(textproperty, value); } } }
now i'm using user control such:
<local:textboxwithvalidation text="{binding path=dummy.myproperty}" />
and dummy entity defined by:
public class dummy : inotifypropertychanged, idataerrorinfo { private string _myproperty; public string myproperty { { return _myproperty; } set { _myproperty = value; onpropertychanged("myproperty"); } } #region idataerrorinfo members public string this[string columnname] { { return "this error"; } } public string error { get; private set; } #endregion #region inotifypropertychanged members public event propertychangedeventhandler propertychanged; #endregion protected virtual void onpropertychanged(string propertyname) { propertychangedeventhandler handler = propertychanged; if (handler != null) handler(this, new propertychangedeventargs(propertyname)); } }
Comments
Post a Comment