private void MainWindow1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { AppViewModel appViewModel = DataContext as AppViewModel; if (appViewModel != null && !appViewModel.CloseApp()) { e.Cancel = true; } }