This is not exclusive to ShowDialog (), Show () does this too. And no, there is no IsDisposed property to check. IsLoaded is only half the solution, it will be false for the first call.
The first approach is to simply make a dialog that can be re-displayed:
public bool CloseAllowed { get; set; } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!CloseAllowed) { this.Visibility = System.Windows.Visibility.Hidden; e.Cancel = true; } }
The following is to explicitly track the health of an object link:
private Window1 win = new Window1(); // say private void button1_Click(object sender, RoutedEventArgs e) { if (win == null) { win = new Window1(); win.Closing += delegate { win = null; }; } win.ShowDialog(); }
Hans passant
source share