我正在尝试从 WPF 应用程序中的子窗口关闭主窗口。问题是,一旦我尝试“关闭”主窗口,我的整个应用程序就会关闭。
这是我在主窗口(pgLogin)中的编码:
Window nextWindow = null;
nextWindow = new pgDashboard();
nextWindow.Owner = this;
this.Hide();
nextWindow.Show();
还有我的子窗口(pgDashboard):
public static T IsWindowOpen<T>(string name = null) where T : Window
{
var windows = Application.Current.Windows.OfType<T>();
return string.IsNullOrEmpty(name) ? windows.FirstOrDefault() : windows.FirstOrDefault(w => w.Name.Equals(name));
}
private void HAZEDashboard_Loaded(object sender, RoutedEventArgs e)
{
var credentials = this.Owner as pgLogin;
credentials.txtEmailAddress.Text.ToString();
var window = IsWindowOpen<pgLogin>();
if (window != null)
{
window.Close();
}
}
有没有办法关闭主窗口而不隐藏它并仍然保持打开我的子窗口?
转到应用程序 App.xaml 并更改“ShutdownMode”,例如更改为“OnExplicitShutdown”。
默认值为 ShutdownMode="OnMainWindowClose" ,这会导致您所描述的行为。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)