Possible Duplicate:
How can I assign the 'Close on Escape-key press' behavior to all WPF windows within a project?
I want to close the windows in my wpf project when the user clicks the escape button. I don't want to write the code in every window but want to create a class which can catch the when the user press the escape key.
Best Answer
Option 1
Use Button.IsCancel property.
However, this works properly only for Dialogs.
Option2
You add a handler to PreviewKeyDown on the window if you want to close windows on Esc press.