KeyPress in winforms was just perfect for input parsing,
unfortunately WPF don't have such event ;(
here my metod for parsing textbox input, allowing to input signed decimal number
(code is sucks but i cant find simpler way)
private void textBox1_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
if (!char.IsNumber(e.Text, e.Text.Length-1))
{
e.Handled = true;
}
if (( (e.Text).ToCharArray()[e.Text.Length - 1] == '.') || ((e.Text).ToCharArray()[e.Text.Length - 1] == ','))
{
e.Handled = true;
if (!(((TextBox)sender).Text.Contains('.')))
{
if (((TextBox)sender).Text.Length == 0) { ((TextBox)sender).Text = "0."; ((TextBox)sender).CaretIndex = ((TextBox)sender).Text.Length; }
else { ((TextBox)sender).Text += "."; ((TextBox)sender).CaretIndex = ((TextBox)sender).Text.Length; }
}
}
if ((e.Text).ToCharArray()[e.Text.Length - 1] == '-' & !((TextBox)sender).Text.Contains('-')) { e.Handled = true; ((TextBox)sender).Text = "-" + ((TextBox)sender).Text; ((TextBox)sender).CaretIndex = ((TextBox)sender).Text.Length; }
if ((e.Text).ToCharArray()[e.Text.Length - 1] == '+' & ((TextBox)sender).Text.Contains('-')) { e.Handled = true; ((TextBox)sender).Text=((TextBox)sender).Text.Substring(1); ((TextBox)sender).CaretIndex = ((TextBox)sender).Text.Length; }
}