WPF: How do I prevent users from entering text in a Textbox data bound to a numeric property?
views:
145answers:
1
+1
A:
The standard validation will handle this...
You can also use a Behavior or attached property to override TextBox's input to prevent non-numeric numbers from being entered. Here is a sample behavior that does this.
Reed Copsey
2010-02-24 20:22:50
I like the phrase "standard validation". Where can I learn more about this?
Jonathan Allen
2010-02-24 20:58:30
Here's a good article on validation in WPF: http://www.codeproject.com/KB/WPF/wpfvalidation.aspx
sparks
2010-02-24 21:02:09
@Jonathan: Just realize that the "standard" way of validating in WPF is to let them type in Text, but show an error. By using a behavior, you can make it so they can't type in text to begin with...
Reed Copsey
2010-02-24 21:24:00
I understand, but I figure knowing both options will be important in the long run.
Jonathan Allen
2010-02-24 22:12:09