Hi,
I am running an addin in Word that allows the user to call a WPF window and close it. The user should be able to open another window by clicking the same button again. The following code snippet shows my current implementation of this:
MainWindow win = new MainWindow(graph); //create MainWindow object if (System.Windows.Application.Current == null) { System.Windows.Application app = new System.Windows.Application { ShutdownMode = ShutdownMode.OnExplicitShutdown }; app.Run(win); } else { System.Windows.Application.Current.Shutdown(); System.Windows.Application app = new System.Windows.Application { ShutdownMode = ShutdownMode.OnExplicitShutdown }; app.Run(win); }
Whenever the the user closes the first opened window and tries to open a new one, the following error gets thrown:
Cannot create more than one System.Windows.Application instance in the same AppDomain.
I added the ShutdownMode parameter since I got the error: "The Application object is being shut down" before. However, it seems like the app object is still hanging around preventing me from creating a new window. How can I kill this object for good when detecting that
System.Windows.Application.Current =! null
Alternatively, how I can I run multiple windows using the same app object without getting the "The Application object is being shut down" error?
Any help is greatly appreciated.
Thanks,
Michael