How to create a TextBox in WPF that accepts numeric values only?

If you want to create a TextBox that accepts numeric values only, you can do this by writing this code on KeyPress event handler of a TextBox.

private void MyTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
          e.Handled = !Char.IsDigit(e.KeyCode);
}

This code will make sure your TextBox accepts input only when the text is a numeric value.