Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default "ok" and "cancel" buttons

Tags:

c#

wpf

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!

like image 502
Phone Developer Avatar asked Nov 05 '11 13:11

Phone Developer


People also ask

What will happen if you choose OK instead of canceling this dialog box?

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 should cancel button do?

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.

Should cancel be on left or right?

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.


1 Answers

There are properties on the button for that: IsDefault & IsCancel

Set them to true on the respective buttons.

like image 133
H.B. Avatar answered Oct 09 '22 22:10

H.B.