c# - WPF binding TextBox to integer property without throwing exception -
i binding textbox.text int
property:
<textbox text="{binding lines, updatesourcetrigger=propertychanged}" /> private int _lines = 10; public int lines { { return _lines; } set { _lines = value; } }
everything works expected simple code, there validation textbox. there exception system.formatexception
thrown in output log. question is:
there elegant way rid of exception without reimplementing everything myself?
mean validators, convertors, etc. ton of code not call int32.tryparse
instead of int32.parse
. not exception thrown , handled wpf big problem, full log makes finding actual problems more difficult.
the question isn't clear, assume referring exception occurs if user enters invalid text (i.e. non-numeric, non-integer data).
afaik, wpf not include built-in control restricts user input. options are:
- use 1 of the several third-party implementations of wpf masked text-box control.
- host
system.windows.forms.maskedtextbox
control in wpf program, i.e. using windowsformshost. - use custom validation in regular
textbox
control process input , avoid having wpf make failed attempt parse invalid text. - live exception.
Comments
Post a Comment