I have a WPF application written in C#. This application has dialog windows in it. Each of these dialogs have a "Save" and "Cancel" button. When a user presses "Enter" on the keyboard, I want to automatically "press" the "Save" button. When a user presses "Esc" on their keyboard, I want to simulated clicking the "Cancel" button. Is there a clean way to do this in WPF?
Thank you!
On a dialog box, clicking the 'Ok' button means the user wants the system to act. Clicking the 'Cancel' button means the user wants to go back to the original screen.
What does the Cancel button do exactly? It dismisses the user's current screen and brings them back to their previous one. This dismissive button is a safeguard to prevent unwanted changes to the system.
In most languages, people are accustomed to read from left side to right side, so it accords with our speech habits to put ok-key on the left side of cancel-key. 2. “Ok/cancel” type make it easier to see and select ok-key.
There are properties on the button for that: IsDefault
& IsCancel
Set them to true on the respective buttons.
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