Home > DeveloperSection > Forums > How to make a textbox which is only accept the numeric value in WPF
C G E Mannerheim
C G E Mannerheim

Total Post:29

Posted on    July-18-2013 3:05 AM


 1 Reply(s)
 1586  View(s)
Rate this:

Hello Mindstick!

I need to make a textbox in wpf application which is accept only numeric value.

thanks in advance

shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Posted on    July-18-2013 11:22 PM

Hi !
try this

private void myTextBox_PreviewKeyDown(object sender, KeyEventArgs e)


            switch (e.Key)


                case Key.D0:

                case Key.D1:

                case Key.D2:

                case Key.D3:

                case Key.D4:

                case Key.D5:

                case Key.D6:

                case Key.D7:

                case Key.D8:

                case Key.D9:

                case Key.NumLock:

                case Key.NumPad0:

                case Key.NumPad1:

                case Key.NumPad2:

                case Key.NumPad3:

                case Key.NumPad4:

                case Key.NumPad5:

                case Key.NumPad6:

                case Key.NumPad7:

                case Key.NumPad8:

                case Key.NumPad9:

                case Key.Back:



                    e.Handled = true;




Don't want to miss updates? Please click the below button!

Follow MindStick