在我的应用程序中,除了我的MainWindow之外,我还有另外一个窗口,我像这样重写了关闭方法,因为我不希望这个窗口完全关闭:
private void Window_Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
this.Visibility = Visibility.Hidden;
}然后在构造函数中:
public Inputwindow()
{
InitializeComponent();
this.Closing += Window_Closing;
}但是现在如果我想关闭我的MainWindow,它只会隐藏MainWindow。
不知道该怎么让它起作用。
发布于 2016-08-08 20:24:13
每个WPF应用程序都有一个名为Application.ShutdownMode的属性,它决定应用程序何时实际结束。默认情况下,它被设置为OnLastWindowClose,这意味着应用程序在关闭所有窗口(即使主窗口关闭)之前不会结束。听起来,您希望应用程序在主窗口关闭时结束,即使其他窗口没有关闭,只是隐藏,这将对应于OnMainWindowClose模式。以下是相关的MSDN文档:https://msdn.microsoft.com/en-us/library/system.windows.application.shutdownmode(v=vs.110).aspx
若要在xaml中设置属性,请打开App.xaml文件并添加如下所示的ShutdownMode属性:
<Application x:Class="TestClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ShutdownMode="OnMainWindowClose">
</Application>https://stackoverflow.com/questions/38837748
复制相似问题