I am trying to keep one instance of a Window
around and when needed call ShowDialog
. This worked find in winforms, but in WPF I recieve this exeception:
System.InvalidOperationException: Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed.
Is there any way to do something like this in WPF?
MyWindow.Instance.ShowDialog();
public class MyWindow : Window
{
private static MyWindow _instance;
public static MyWindow Instance
{
if( _instance == null )
{
_instance = new Window();
}
return _instance();
}
}