title: control numeric textbox's numeric value
body: <p>I have a <code>TextBox</code> and I want it to be numeric only. Thus, I googled and found <a href="https://stackoverflow.com/questions/17505008/numeric-textbox-in-c-sharp-wpf">this</a> stackoverflow post which helped me already a lot. However, I want the, now numeric only, textbox to show a warning when I enter something underneath 20. At first, I tried the event <code>OnTextInput</code>, and after no success I tried to handle it in the same event as the numeric stuff <code>OnPreviewTextInput</code>. I used the same code for both.</p>
  
  <pre><code>if (!char.IsDigit(e.Text, e.Text.Length - 1))
  {
      var text = e.Text;
      int num;
  
      var success = int.TryParse(text, out num);
      if (!success)
          return;
  
      if (num &lt;= 20)
      {
          if (MessageBox.Show("Are you sure you want to go underneath 20?",
                              "... You sure?", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) ==
                          MessageBoxResult.Yes)
                            e.Handled = true;
  
           else
           {
              num++;
              textBox.Text = num.ToString();
           }
      }
  
                  e.Handled = true;
  }
  </code></pre>