To process a Backspace or other key pressed to cancel it, try using the PreviewKeyDown event handler.
In your Xaml, set the PreviewKeyDown attribute as follows:
<TextBox PreviewKeyDown="textBox1_PreviewKeyDown" ...
and in your code, define an event handler as follows:
private void textBox1_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Back || e.Key == Key.Delete) { e.Handled = true; } }
Hop that helps :)
Guidemmpty
source share