I have an application where at one point I am closing all windows and I want to relaunch one of the closed windows. But the problem is when I say Window.Show(); the breakpoint shows the Actual Height and Actual Width to be 0 and after the line is executed, the entire app shuts down. Why, is it being garbage collected?
private void btnCancel_Click(object sender, RoutedEventArgs e) { if (jsonAssayViewModel.IsLiveProgress) { var res = Xceed.Wpf.Toolkit.MessageBox.Show( Application.Current.TryFindResource("CloseRun").ToString(), "Confirm dialog", MessageBoxButton.YesNo, MessageBoxImage.Question ); if (res == MessageBoxResult.No) { jsonAssayViewModel.PreventClosingWindow = true; return; } } //Raise the close event.... if (CloseCurrentProgressWindow != null) { CloseCurrentProgressWindow(); } var window = Window.GetWindow(this); if (window != null && window.Tag.ToString() == "Success") { if ((sender as Button).Content.ToString() == Application.Current.TryFindResource("Done").ToString()) { var AllWindows = Application.Current.Windows.Cast<Window>() .Where(win => win.IsLoaded); if (AllWindows.Count() > 2) { jsonAssayViewModel.SelectedAssay = null; jsonAssayViewModel.SelectedVolume = string.Empty; foreach (Window win in App.Current.Windows) { win.Close(); } NextGenDGRunSetupWindow wn = new NextGenDGRunSetupWindow(); wn.Show(); } } } } And in the NextGenDGRunSetupWindow I have the following
public NextGenDGRunSetupWindow() { InitializeComponent(); //idleTimeDetector = new IdleDetector(this); //1 minute readJsonViewModel = ReadJsonAssayViewModel.ReadJsonAssayViewModelInstance; //idleTimeDetector.IsIdle += IdleTime_IsIdle; readJsonViewModel.LaunchErrorWindowFromAnywhere += ReadJsonViewModel_LaunchErrorWindowFromAnywhere; }
foreach (Window win in App.Current.Windows) {win.Close();}. This will also close your main program window -- which is akin to saying goodbye to your program, unless you change the ShutdownMode of your application.