Topics: Prism v4 - WPF 4
Dec 9, 2015 at 11:01 AM
Edited Dec 9, 2015 at 11:04 AM
Is it possible in Prism 5 to pass the closing event args to a command?
Dec 9, 2015 at 11:16 AM
Yes - and in Prism 6 (http://github.com/PrismLibrary/Prism). Add an InvokeCommandAction behavior to the main Window, with its EventTrigger hooked up to the Closing event, set the Command property of the InvokeCommandAction to a static CompositeCommand defined in your app, and the CancelEventArgs of the Closing event will be passed to any registered commands anywhere in the app that Register with the CompositeCommand.

Dec 9, 2015 at 11:19 AM
Thanks for the rapid response Brian, but I think I will hang on to 5 for the time being as everything is working :-)

Can this still be done in 5, if so how?
Dec 9, 2015 at 11:38 AM
Same exact answer, Prism's InvokeCommandAction was added in Prism 5.
Dec 9, 2015 at 12:27 PM
Ah sorry Brian, thank you
Dec 9, 2015 at 12:54 PM
Bit of a long shot but I don't suppose you know how I would trigger this on a user control rather than a window, no worries if not
Dec 9, 2015 at 1:25 PM
I don't think it is possible since the Closing event will only be raised on the Window object, so the trigger would have to be attached to the Window.
Dec 9, 2015 at 1:32 PM
I have the following Brian but it only works once, the application goes to close then springs back up but the handler seems to have disappeared.
  public SettingsContent()
            Loaded += UserControl_Loaded;
            vm = DataContext as SettingsContentViewModel;


        void UserControl_Loaded(object sender, RoutedEventArgs e)
            _parentWindow = Window.GetWindow(this);
            if (_parentWindow != null) _parentWindow.Closing += parentWindow_Closing;

        void parentWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)


Dec 9, 2015 at 3:20 PM
Not sure exactly what you are describing as the problem, but here is another old post of mine with another approach that might shed some light:
Dec 9, 2015 at 3:55 PM
That looks like what I need but the links return 404 :-(
Dec 9, 2015 at 4:15 PM
Hmm, working fine from my machine and my phone, try again. I was doing some blog maintenance back around the time I answered.
Dec 9, 2015 at 4:56 PM
Edited Dec 9, 2015 at 4:57 PM
I have now managed to download it but it wont build, tried it in 2013 and 2015, enabled NuGet restore. Under the CAL folder it says the 3 elements are unavailable, am I missing something?
Dec 9, 2015 at 6:45 PM
I pointed you at that to take a look at the code. It is not realistic to expect a 7 year old sample to build and run in todays tools.
Dec 10, 2015 at 8:57 AM
No problem, thanks for your help