我在 wpf 中有一个窗口,我想在退出按钮上关闭窗口。所以我在 PreviewKeyDown 事件上写了这段代码,但它关闭了整个应用程序,包括主窗口和当前窗口。我只想关闭当前窗口。
//this code for open second window
private void M_Mahale_Click(object sender, RoutedEventArgs e)
{
Tanzimat.MahaleWin Mahale = new Tanzimat.MahaleWin();
Mahale.ShowDialog();
}
//this code for PreviewKeyDown event on second window and current window
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.Close();
}
}