wpf - Textbox Binding to a double property returns Error Message when entering not a number value in MVVM -
wpf - Textbox Binding to a double property returns Error Message when entering not a number value in MVVM -
i have textbox binding double property. here xaml
<textbox grid.column="1" horizontalalignment="stretch" margin="0,0,0,15" name="textbox_algorthwheight" verticalalignment="center"> <textbox.text> <binding path="algorithmweight" stringformat="n1"> <binding.validationrules> <exceptionvalidationrule/> </binding.validationrules> </binding> </textbox.text> </textbox>
the property code shown below
public double algorithmweight { { homecoming _algorithmweight; } set { if (value < 1.0) { value = 1.0; } _algorithmweight = value; onpropertychanged("algorithmweight"); } }
mvvm wpf take care of exception when come in non number value highlight textbox in reddish colour want add together error message next text box notify user value not acceptable, , utilize previous value or default value. give thanks in advance
you should implement idataerrorinfo. see here tutorial, show how create message , style textbox when error present: link
wpf mvvm binding textbox
Comments
Post a Comment