protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); ControleurRIBPage controleurRIBPage = MainFrame.Content as ControleurRIBPage;// Allows to call the function to release the Excel file from use when closing the main window (which shuts down the application in the current setup) VMControleurRIB vMControleurRIB = controleurRIBPage.DataContext as VMControleurRIB; if (vMControleurRIB.ExcelApp != null) { if (vMControleurRIB.ExcelApp.IsOpen) { vMControleurRIB.ExcelApp.Terminate();// Automatically releases the previous file when the user loads a new one without releasing first. } } }
public ControleurRIBPage() { InitializeComponent(); DataContext = new VMControleurRIB(); }