I wonder if it's possible to make KeyDown event trigger before TextChanged?
I have added these two events for a simple TextBox and now I want to check if Delete key was pressed. If yes, <do nothing>, if no <so something>. I have created a boolean field, that "remembers" if I pressed Delete, but the problem is KeyDown triggers after TextChanged, so it doesn't work...
To cancel Keydown event you can add a PreviewKeyDown:
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if(e.Key == Key.Delete)
e.Handled = true;
}
what about PreviewKeyDown event?
Edit:
PreviewKeyDown event is a tunneling routed event, it travels down the containment hierarchy.
KeyDown event is a bubbling routed event, it travels up the containment hierarchy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With