WPF: Enter/Esc key as shortcuts of OK/Cancel buttons

DialogBox is the easiest example that comes, but 99% of windows should have shortcuts for “OK” and “CANCEL” button.
The keys supposed to be the shortcut keys are always the same: ENTER and ESC key.
In XAML, you can set up this shortcut in button properties, via IsDefault and IsCancel properties.

Here is an example:


<Button Name="btnOK" IsDefault="True">OK</Button>
<Button Name="btnCancel" IsCancel="True">CANCEL</Button>

source: Dialog Boxes Overview

Advertisements

Tags: ,


%d bloggers like this: