Phone Developer
Phone Developer

Reputation: 1461

Set default "ok" and "cancel" buttons

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!

Upvotes: 7

Views: 6012

Answers (1)

brunnerh
brunnerh

Reputation: 185290

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

Set them to true on the respective buttons.

Upvotes: 21

Related Questions