UserControl close with Prism

Topics: Questions
Apr 1, 2014 at 8:55 AM
I'm using catel with prism. I'm loading different modules at runtim, each has its own view and viewmodel. I have a problem especially when closing the program. Here the OnClosing event in the ViewModel is not fired. I have also tried this in the catel examples, same behaviour too. My View is a catel:UserControl and the ViewModel derives from the ViewModelBase. Is there a way to fire on each UserControl the OnClosing event when the program is closing?

Regards Markus
Apr 1, 2014 at 9:01 AM
The ViewModel.OnClosing event fires when the view is being unloaded. Apparently the view does not invoke the Loaded event when closing the application.

What I recommend is to use the NavigationService instead and subscribe to one of the following events:
  • public event EventHandler<ApplicationClosingEventArgs> ApplicationClosing;
  • public event EventHandler<EventArgs> ApplicationClosed;
Marked as answer by Rawukal on 4/1/2014 at 1:25 AM
Apr 1, 2014 at 9:25 AM
Simple and effective!!! Thank you very much!!!

Regards Markus