简体   繁体   中英

WPF: Unable to raise Window.Closing event from app module

I take charge of a development of an older WPF modular application using Prism Library for WPF . In this case, entry point to the application for me is an overriden Initialize() method since I have no access to the Application.MainWindow 's App class. This class along with some other helper classes is compiled to EXE file and DLL's.

Currently I'm facing to a problem that I have to catch the Window.Closing event which is not raised during closing the application. Normally this piece of code which is put into the constructor (in this specific case into Initialize() method) is working as expected

Application.Current.MainWindow.Closing += (s, e) =>
{
  e.Cancel = true;
};

On the other hand, event Window.Closed is fired up without any issues.

In my opinion it's not possible to associate this event handler outside of Application.MainWindow 's constructor, or do I something wrong? Please help me.

The issue was located. The OnClosing method which raises the Closing event is implemented in the shell and it looks like this

protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
     e.Cancel = true;
     ViewModel.StartShutdownSequence();
}

The StartShutdownSequence() encapsulates some logic regarding handling individual modules and at the end it calls Application.Current.Shutdown() which definitely shutdown the application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM