Close shell without closing app

Jun 7, 2013 at 3:39 PM
I have a hybrid non-MVC/MVC app using the framework and MVC only for the reporting features. When the user is finished with the reporting module I'd like to close the shell without terminating the entire application as it does when invoking ApplicationShutdownViewAction. Is there a method that can be used to close the shell or, if not, what would the best approach be?
Jun 7, 2013 at 5:47 PM
Edited Jun 7, 2013 at 5:48 PM

How do you start the application - is it started directly by the user or spawned from another app?

If the shell is closed, what do you want to have happen next since the shell is the main platform for the user to interact with the app?

You could add an event to the Closing Eventhandler in the StartViewModel where you would use e.cancel = true; but then that would keep the shell open.

You might try adding another method (via Controller.RegisterViewHandler() ) to the Startup event handler in App.xaml.cs (I haven't tried this) and see if that fires.

I have noticed that if I close the shell, the application stays running (at least in development mode) because the ViewVisualizer is there to hold hit up. So another option is to create something equivalent (since you need to have some sort of interface for the user to use to close your app.)

In my case, I need code to fire when the user closes the app so I added an event to the ApplicationEx.Currennt.Exit event handler. In my case, this method does some clean up work as I spawn some processes in startup and need to make sure they are shut down since otherwise, they will stay running after I exit - and do if I just hit the red stop square during debug sessions.)

So I didn't quite answer your question, but gave you some ideas of things to try. Without knowing more about what you are trying to do, I really can't give you a "best" answer.

Jun 9, 2013 at 1:43 AM
Good points, thanks for the reply, Fletcher.

Generally speaking, in WPF, the app stays alive as long as there is a Window open. So just closing the Shell should not terminate the entire app. So if instead of using the standard action to terminate the app, you just say this...
...the app should stay up and running.

Jun 9, 2013 at 3:27 AM
"...the app should stay up and running"

and indeed it does! That was easy enough. I may have been overthinking the structure a bit. Thanks to Markus and FletcherJ for your responses.
Jun 11, 2013 at 1:02 AM

But I hate it when I over think something and Markus comes up with a really simple way to do it.... :)

Glad it's working for you,

Jul 1, 2013 at 9:13 PM
That is the main thing that I see people having trouble with. Especially people who have done WPF/XAML work before are starting to think in such complex terms, it is often difficult to do the simple things. In many of our consulting engagements, I spend the majority of time simplifying code :-)