When closing my main window(pgLogin) from a child window(pgDashboard), my child window does not want to display at all. In my previous question I set the "ShutdownMode" to "OnExplicitShutdown", so that when I close my main window, the whole application does not shut down. Only thing now is that my application does not shut down, but my child window does not display at all.
Here is my coding from my main window(pgLogin):
Window nextWindow = null;
nextWindow = new pgDashboard();
nextWindow.Owner = this;
this.Hide();
nextWindow.Show();
And my child window(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();
}
}
Any idea why this could be happening?
EDIT: Just did a test, and I can see that when I close the main window, my child window also closes for some reason, because when I try to call this.Show(); on my child window, it gives me this error:
Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed.
EDIT 2: I think the problem might be caused because I set the main window(pgLogin) as the owner of the child window(pgDashboard)?