Is there any straightforward way of telling the whole WPF application to react to Escape key presses by attempting to close the currently focused widow? It is not a great bo
create RoutedUICommand like below
private static RoutedUICommand EscUICommand = new RoutedUICommand("EscBtnCommand"
, "EscBtnCommand"
, typeof(WindowName)
, new InputGestureCollection(new InputGesture[]
{ new KeyGesture(Key.Escape, ModifierKeys.None, "Close") }));
and add it command binding in constructor
CommandBindings.Add(new CommandBinding(EscUICommand, (sender, e) => { this.Hide(); }));