c# - WPF Handling Window taskbar closing event -


i have problem in wpf application. when close application window task bar (close window) or press alt + f4 never hits application_exit event handler in app.xaml file.

<application x:class="wpfapplication.app"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                           startup="application_startup" exit="application_exit"> 

code behind

private void application_exit(object sender, exiteventargs e) {     application.current.shutdown(); } 

you have set

shutdownmode="onexplicitshutdown" 

on app.xaml (or in code behind).

therefore need set listener on closed event of mainwindow, calling shutdown method.

or have set

shutdownmode="onlastwindowclose" 

then have window open, besides mainwindow.


Comments