Possible Duplicate:
Notification when WPF UI closes
I have asked a very similar question before, but i did not get any usable response. I am hoping that someone out there might be able to help me.
I have an existing tray app programmed as a Windows Form app. I have an existing Settings form programmed as WPF.
The Tray App needs to be able to: * Open the Settings App n times, with only one instance ever opened at a time * Receive notification when the user closes the Settings App.
The Settings App uses a ResourceDictionary, which I believe means it must be started from App.xaml.
I can get the Settings window to open once and notify the Tray when it is shut down using the following code, but I cannot get it to open again.
if (gui == null)
{
//shell = new mainWindow();
//shell.CloseEvent += settings_FormClosed;
gui = new App();
//gui.ShutdownMode = ShutdownMode.OnExplicitShutdown;
gui.MainWindow = shell;
gui.InitializeComponent();
//gui.Run();
gui.Exit += new System.Windows.ExitEventHandler(settings_FormClosed);
IsUIOpen = true;
}
If I uncomment the lines above, I can then intercept the close event, and set the Visibility to Hidden. The next time the user selects Settings, I can set it back to Visible. However, the first time Settings opens, it will not trigger the Exit event and shell is not getting all the ReferenceDictionary (or losing access to it), so the window is not displaying properly.
Is there a way to run WPF from the app, and access MainWindow (which often seems to be null, and is not of the type of my own window) so a custom listener can be added to mainWindow?
Alternately, is there a way to dispose of the static App so I can re-instantiate it the next time the user clicks on Settings.
I know there must be some way to get WPF to play nice with Win Forms. Thank you to everyone who attempts to help. This has been giving me major headaches.