title: Create WPF TextBox that accepts only numbers
body: <p>I would like to create a TextBox that only accepts numeric values, in a specific range.
  What is the best way to implement such TextBox?</p>
  
  <p>I thought about deriving TextBox and to override the validation and coercion of the TextProperty. However, I am not sure how to do this, and I understand that deriving WPF control is generally not recommended.
  <hr>
  <b>Edit:</b><br/>
  What I needed was a very basic textbox that filters out all key presses which are not digits.
  The easiest way to achieve it is to handle the TextBox.PreviewTextInput event:</p>
  
  <pre><code>private void textBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
  {
      int result;
      if (!validateStringAsNumber(e.Text,out result,false))
      {
          e.Handled = true;
      }
  }
  </code></pre>
  
  <p>(validateStringAsNumber is my function that primarily use Int.TryParse)</p>
  
  <p>Some of the suggested solutions are probably better, but for the simple functionality I needed this solution is the easiest and quickest to implement while sufficient for my needs.</p>