24 lines
594 B
C#
24 lines
594 B
C#
using System.Windows;
|
|
using System.Windows.Input;
|
|
|
|
namespace Explorer.App;
|
|
|
|
/// <summary>
|
|
/// Close helpers for windows opened with <see cref="Window.Show"/>.
|
|
/// <see cref="Button.IsCancel"/> sets <see cref="Window.DialogResult"/>, which throws on modeless windows.
|
|
/// </summary>
|
|
internal static class ModelessWindowClose
|
|
{
|
|
public static void EnableEscape(Window window)
|
|
=> window.PreviewKeyDown += (_, e) =>
|
|
{
|
|
if (e.Key != Key.Escape)
|
|
{
|
|
return;
|
|
}
|
|
|
|
window.Close();
|
|
e.Handled = true;
|
|
};
|
|
}
|