views:

145

answers:

1

WPF: How do I prevent users from entering text in a Textbox data bound to a numeric property?

+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
I like the phrase "standard validation". Where can I learn more about this?
Jonathan Allen
Here's a good article on validation in WPF: http://www.codeproject.com/KB/WPF/wpfvalidation.aspx
sparks
@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
I understand, but I figure knowing both options will be important in the long run.
Jonathan Allen