WPF Hitting Enter when focus on command button passes Enter key through to next control for handling

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a button on a WPF window that, when clicked, opens up a dialog window where I need to get some text from the user. If I tab to the button, so it has focus, and then hit the Enter key, it opens up the dialog window and gives it the enter key to handle (which of course ends the dialog window).
How do I handle the Enter key in the button, and get rid of it before going to the dialog window? Ive tried the KeyDown and KeyUp events but they arent being triggered. Ive tried the PreviewKeyDown event, but the enter key goes to the Dialog window, comes back, and THEN goes into the PreviewKeyDown event code (ie, too late).
How can I stop the enter key from being passed into the dialog window?

View the full article
 
Back
Top