Gracefully closing applications using WPF PRISM 4

I am looking for a “best practice” (if there is even a better one) to cleanly close a WPF application using MEF and PRISM4. Ultimately, I'm looking for some kind of “Close Service” that will manage the entire event / command from the shell for any view model (or other subscribers) who want to confirm this in order to close the application. Is an event aggregator the cleanest way? Other opinions / options?

Ideally, I would have a button on my ToolbarView in my ToolbarRegion (1 of 2 regions in my shell). This button will call a command on my ToolbarViewModel (referring to a command on my ToolbarControler), which in turn will do 2 things (I think?) ... First, notify all subscribers that it is closing time and allows any of them to cancel the closure and ... secondly, if they are not canceled, somehow notify the shell of the closure. The application shutdown mode is set to "ShutdownMode.OnMainWindowClose", so if the shell closes, I must be installed.

Can someone help me with this?

+5
source share
1 answer

, : MEF PrismV4

-:
"" "", .
, , tabcontrol, IDisposable . ( , tabcontrol, , ).
, IDisposable , .., , " ", ? =)

EventAggregator: , : , , . .

, , :

public interface IShutdownAware
{
   bool CanShutdown();
}

, dispose, CanShutdown();, true, , .

+3

All Articles