WPF Binding and Validation -
i have issue validation in wpf can't seem resolve. have class (that implements idataerrorinfo) uses property like-so.
private double? _sizesearchvalue; public double? sizesearchvalue { { return _sizesearchvalue; } set { _sizesearchvalue = value; notifychange("sizesearchvalue"); validateinputrow("sizesearchvalue"); } }
it bound textbox in xaml this.
<stackpanel orientation="horizontal"> <textblock verticalalignment="center" text="size:"/> <combobox text="{binding sizesearchoption, validatesondataerrors=true}"/> <textbox text="{binding sizesearchvalue, validatesondataerrors=true, updatesourcetrigger=propertychanged, validatesonexceptions=false}"/> </stackpanel>
the validateinputrow() function in property setter go through , run custom validation routines , set errors appropriately combobox , textbox in stackpanel mention above have red border. works fine until put non-numeric string textbox ("abc" example.)
with string input binding runs default validation, formatexception raised , textbox gets red border per usual. problem custom validation routine never run because property setter in class never called.
i understand why happening, wondering if knew way catch event, or offending formatexception can run custom validation after fact. can't seem figure 1 out.
ok, looks answered own question. looked further formatexception stack trace , found 'ivalueconverter' involved in process so..... solution use converter so:
<textbox text="{binding sizesearchvalue, validatesondataerrors=true, updatesourcetrigger=propertychanged, converter={staticresource testconverter}}"/>
in case whipped 1 (testconverter) real quick , tied custom validation rules. problem solved. wonder if there equivalent solutions problem?
Comments
Post a Comment