protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
#endif
if (e.Handled)
{
return;
}
if (Keyboard.Modifiers != ModifierKeys.None)
{
return;
}
if (e.Key == Key.Enter)
{
if (_defaultOkElement != null)
{
_defaultOkElement.GotFocus += OnButtonReceivedFocus;
if (!_defaultOkElement.Focus())
{
HandleDefaultButton();
}
e.Handled = true;
}
else if (_defaultOkCommand != null)
{
HandleDefaultButton();
e.Handled = true;
}
// Else let it go, it's a custom button
}
if (e.Key == Key.Escape && CanCloseUsingEscape)
{
if (_defaultCancelCommand != null)
{
Log.Info("User pressed 'Escape', executing cancel command");
// Not everyone is using the ICatelCommand, make sure to check if execution is allowed
if (_defaultCancelCommand.CanExecute(null))
{
_defaultCancelCommand.Execute(null);
e.Handled = true;
}
}
else
{
Log.Info("User pressed 'Escape' but no cancel command is found, setting DialogResult to false");
if (!SetDialogResultAndMakeSureWindowGetsClosed(false))
{
Close();
}
e.Handled = true;
}
}
}