문제

How can I forbid the Backspace-Key as easy as possible in a WPF-Application?

The KeyDown-Event don't catch at the DEL and the Backspace-Key.

Thank you!

도움이 되었습니까?

해결책

To handle Backspace or other pressed key in order to cancel it, try to use the "PreviewKeyDown" event handler.

In your Xaml, set the attribute PreviewKeyDown like this :

<TextBox PreviewKeyDown="textBox1_PreviewKeyDown" ...

and in your code, define the event handler like this :

private void textBox1_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Back || e.Key == Key.Delete)
    {
        e.Handled = true;
    }
}

Hop that helps :)

다른 팁

Try overriding OnTextInput(...).

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top