wpf - Error message in a property -
this problem. if user type number in textbox right, if type char, don't see messagebox () in property. why ?
<textbox horizontalalignment="left" tabindex="12" text="{binding time_hh, updatesourcetrigger=propertychanged,stringformat='{}{##}'}" flowdirection="righttoleft" maxlength ="2" height="30" width="30" />
and property
private _time_hh integer public property time_hh() integer return _time_hh end set(value integer) = 0 len(value.tostring) if isnumeric(value.tostring(i)) = false messagebox.show("error") value = 0 end if next _time_hh = value onpropertychanged("time_hh") end set end property
your time_hh
property integer, there's no way it's gonna contain non-numeric character.
at most, happen binding fail due type mismatch (is textbox showing red outline?)
if wanna check if user enters non-numeric characters, have use type allows so: string.
try this:
private _time_hh integer public property time_hh() string return _time_hh.tostring() end set(value string) = 0 len(value) if isnumeric(value.tostring(i)) = false messagebox.show("error") value = 0 end if next _time_hh = integer.parse(value) onpropertychanged("time_hh") end set end property
if need use numeric value, use integer field. create second property of type integer exposes field, if want use binding or (remember raise onpropertychanged
property too, then, on time_hh
setter)
caution - code above raise exception if user types "00,01-2,0". isnumeric
returns true
characters in string, doesn't mean correct number.
in opinion, better this:
private _time_hh integer public property time_hh() string return _time_hh.tostring() end set(value string) dim int integer if integer.tryparse(value, int) = false messagebox.show("error") end if _time_hh = int onpropertychanged("time_hh") end set end property
sorry if did mistakes, code in c# , vb pretty rusty :p
Comments
Post a Comment