6

How do I convert a TextBox to int or is there a box inside WPF that supports only numbers?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
divfe
  • 183
  • 1
  • 1
  • 7

2 Answers2

13

To convert string to int you can use, Parse:

string text = "1234";
int value = int.Parse(text);

Or you could use NumericUpDown control.

Alex Aza
  • 76,499
  • 26
  • 155
  • 134
1

If you only want numeric input, you might be better off with numbericupdown. Of course, you could just validate the input using tryparse...

soandos
  • 4,978
  • 13
  • 62
  • 96