tags:

views:

308

answers:

1

Hi

I am working in a WPF application, using C#.net I want to know, is there any way to disable BackSpace button on a particular xaml page. I want to prevent user from using the backspace button on this particular xaml page. Even if the user presses the BackSpace button, no effect should take place.

Thanks

+2  A: 

You'll need to catch the onKeyDown event and set handled to true for backspace.

private void Window_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Back)
    {
         e.Handled = true;
    }
}
sipwiz
If he meant navigation, then the situation might be a bit more complex, as you probably have to handle Alt+Left and some mouse buttons as well.
Joey
This should actually handle the PreviewKeyDown event, otherwise if another control has focus (like TextBox), the key press won't get intercepted. Since he hasn't said why he wants to disable the backspace key, maybe he wants to support it in entry controls.
Abe Heidebrecht
Hey Abe, it worked PreviewKeyDown event.Thanks a lot.