This is a WPF/C# application and I’m having more of a design problem than a code problem.
I have 5 separate *.xaml files implementing a class derived from window. So, 5 windows. This is a wizard-type of application so each window has back/next buttons that will create a new window, hide itself, and show the new window.
This isn’t purely navigation based (so I’m not using pages) because sometimes I want to skip a window, or go back to the first window, etc.
Every time a new window is opened the parent window sets itself as the owner of the new window and hides itself. When the back button is used the new window shows the owner and closes itself. This works fine for navigation.
I’m having a problem when someone actually closes the window as opposed to using the navigation. If they close the window, Alt-F4, hit the X, etc it should close the whole app.
My ‘go back’ button also closes the window, which triggers Window_Closed, closing the whole app.
I’m trying to think of a way to close the whole app when the user closes the window, but close only the window (not hide it, actually dispose of it) and show the owner when they click back. I can’t seem to do the latter without triggering the former.
Any suggestions? I’m just not thinking about this the right way.
Instead of flipping between Windows, I would recommend flipping between UserControls in panels. You have the full functionality of a Window except you don’t have to worry about its open/closed state. Just have the UserControls toggle visibility based on the Next/Previous commands.
You might consider looking into doing navigation for your wizard. You can do this in WPF as demonstrated here.
With navigation, you have a single window that hosts pages. You can then issue a command to navigate to a particular page and it will automatically flip to the page without you having to worry about control visibility.