Hello. When re-opening the modal window an error occurs

Cannot set Visibility or Call Show, ShowDialog, or WindowInteropHelper. EnsureHandle after a Window has closed.

How to eliminate it?

Window w = new Window(); w.ShowDialog(); 

    1 answer 1

     private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { e.Cancel = true; this.Visibility = Visibility.Hidden; }