How to disable the use of the backspace key in WPF

How can I disable Backspace-Key as simple as possible in a WPF application?

Event KeyDown event does not capture DEL and Backspace-Key.

Thanks!

+6
c # wpf keydown keyeventargs
source share
2 answers

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 :)

+14
source share

Try overriding OnTextInput(...) .

Then if(args.Text == "\b") should give you if(args.Text == "\b") .

0
source share

All Articles