How do I intercept a keyboard entry before it is entered into an edit box? I have:
<Window x:Class="X.MainWindow"
        KeyDown="Window_KeyDown"
        >
private void Window_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Add) 
        return;
}//Window_KeyDown
Pressing the "+" button on the numeric section of the keyboard is detected. It also places a "+" into one of my edit boxes. How do I prevent that from happening?
You have already intercepted the key before it gets sent to the Textbox.
Now, set
e.Handled = true;
so that the event does not keep propagating up to the textbox
http://msdn.microsoft.com/en-us/library/system.windows.routedeventargs.handled(v=vs.110).aspx
private void Window_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Add) 
    {
        e.Handled = true; // Prevents the event from propagating further.
        return;
    }
}//Window_KeyDown
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