Q:

How to force textbox to take only numbers in WPF?

I want user to enter only numeric values in TextBox.
I got this code:
private void txtType1_KeyPress(object sender, KeyPressEventArgs e)
{
     int isNumber = 0;
     e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber);
}

But I am not getting textbox_KeyPress event and e.KeyChar while using WPF.
Whats the solution in WPF?
Edit:
I made a Solution! 
private void txtName_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
    CheckIsNumeric(e);
}

private void CheckIsNumeric(TextCompositionEventArgs e)
{
    int result;

    if(!(int.TryParse(e.Text, out result) || e.Text == "."))
    {
        e.Handled = true;
    }
}

A:

protected override void OnPreviewTextInput(TextCompositionEventArgs e)
    {
        char c = Convert.ToChar(e.Text);
        if (Char.IsNumber(c))
            e.Handled = false;
        else
            e.Handled = true;

        base.OnPreviewTextInput(e);
    }

A:

You can use a validation rule...
http://www.codeproject.com/KB/WPF/wpfvalidation.aspx
Or make your own Maskable textbox
http://rubenhak.com/?p=8

