Answered by:
TextBox

Question
-
I have a textbox that I want only mumbers from, not alpha numerics. I remeber on winForms there was a way to set textboxes so the user was only able ot enter 0 - 9. But I can't seem to find it with WPF.
How would I go about making sure only numbers can be entered?Monday, March 2, 2009 3:01 PM
Answers
-
WinForms has a MaskedTextBox control that allows you to do this conveniently. Unfortunately this feature is not yet available in WPF. What you can do instead is to handle the TextChanged event on your WPF TextBox, and filter TextBox.Text to only contain numbers.
- Proposed as answer by J_________ Monday, March 2, 2009 7:22 PM
- Marked as answer by Tao Liang Wednesday, March 4, 2009 2:43 AM
Monday, March 2, 2009 7:22 PM -
Here are 3 ways of doing it...
http://forums.msdn.microsoft.com/en-US/wpf/thread/fb0745f0-6c26-4a9e-b792-3f7e8484b243
http://dedjo.blogspot.com/2007/11/number-only-textbox.html
You can also find a great example here:
http://dotnetus.spaces.live.com/Blog/cns!4E39ECD492E4EEC1!550.entry
http://sharpinsights.wordpress.com/2007/09/28/numeric-value-editor-control-similar-to-ms-expression-blend/
Hope this helps. If you still can't get it to work just let me know. :)Monday, March 2, 2009 10:06 PM
All replies
-
WinForms has a MaskedTextBox control that allows you to do this conveniently. Unfortunately this feature is not yet available in WPF. What you can do instead is to handle the TextChanged event on your WPF TextBox, and filter TextBox.Text to only contain numbers.
- Proposed as answer by J_________ Monday, March 2, 2009 7:22 PM
- Marked as answer by Tao Liang Wednesday, March 4, 2009 2:43 AM
Monday, March 2, 2009 7:22 PM -
Here are 3 ways of doing it...
http://forums.msdn.microsoft.com/en-US/wpf/thread/fb0745f0-6c26-4a9e-b792-3f7e8484b243
http://dedjo.blogspot.com/2007/11/number-only-textbox.html
You can also find a great example here:
http://dotnetus.spaces.live.com/Blog/cns!4E39ECD492E4EEC1!550.entry
http://sharpinsights.wordpress.com/2007/09/28/numeric-value-editor-control-similar-to-ms-expression-blend/
Hope this helps. If you still can't get it to work just let me know. :)Monday, March 2, 2009 10:06 PM -
Or you could use MaskedTextBox in Winform and then host it in WPF.Wednesday, March 4, 2009 2:43 AM