private async void App_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { var deferral = e.GetDeferral(); // Warn user if unsaved project changes exist and allow them to cancel closing the app var page = (Window.Current.Content as Frame)?.Content; if (page is MainPage mainPage && mainPage.ActiveProject != null && mainPage.ActiveProject.HasUnsavedChanges) { var dlg = new MessageDialog( $"Project {mainPage.ActiveProject.Name} has unsaved changes.\nAre you sure you want to exit?", "Warning"); var confirmCommand = new UICommand("Yes"); var cancelCommand = new UICommand("Cancel"); dlg.Commands.Add(confirmCommand); dlg.Commands.Add(cancelCommand); if (await dlg.ShowAsync() == cancelCommand) { e.Handled = true; } } deferral.Complete(); }
private async void Close_Requested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { Deferral deferral = e.GetDeferral(); ContentDialog exitDialog = new ContentDialog { Title = "Exit?", Content = "Have you saved your latest Changes? They otherwise will be lost forever!", CloseButtonText = "Cancel", PrimaryButtonText = "Save", SecondaryButtonText = "Exit", DefaultButton = ContentDialogButton.Secondary }; ContentDialogResult result = await exitDialog.ShowAsync(); if (result == ContentDialogResult.Primary) { e.Handled = true; Save_Click(null, null); } else if (result != ContentDialogResult.Secondary) { e.Handled = true; } deferral.Complete(); }
private async void OnCloseRequest(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { ViewModel.Deferral = e.GetDeferral(); if (ExitApplication == null) { ViewModel.Deferral.Complete(); } else { e.Handled = !(await ExitApplication(ViewModel)); if (!e.Handled) { return; } try { ViewModel.Deferral?.Dispose(); } catch (ObjectDisposedException) { Logger.LogDebug("Handled Deferral already disposed."); } } }
private async void OnCloseRequest(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { if (App.Services.GetService <DialogManager>().CurrentDialogView != null) { e.Handled = true; Logger.LogCritical("Already a dialog open."); return; } ViewModel.Deferral = e.GetDeferral(); if (ExitApplication == null) { ((Windows.Foundation.Deferral)ViewModel.Deferral).Complete(); } else { e.Handled = !(await ExitApplication(ViewModel)); if (!e.Handled) { return; } try { ((Windows.Foundation.Deferral)ViewModel.Deferral)?.Dispose(); } catch (ObjectDisposedException) { Logger.LogDebug("Handled Deferral already disposed."); } } }
private async void SystemNavigationManager_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { Deferral deferral = e.GetDeferral(); ConfirmCloseDialog dlg = new ConfirmCloseDialog(); ContentDialogResult result = await dlg.ShowAsync(); if (result == ContentDialogResult.Secondary) { // user cancelled the close operation e.Handled = true; deferral.Complete(); } else { switch (dlg.Result) { case CloseAction.Terminate: e.Handled = false; deferral.Complete(); break; case CloseAction.Systray: if (ApiInformation.IsApiContractPresent( "Windows.ApplicationModel.FullTrustAppContract", 1, 0)) { await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(); } e.Handled = false; deferral.Complete(); break; } } }
/// <summary> /// Invoked when application is being closed by the user. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void OnClosingAsync(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { var deferral = e.GetDeferral(); if (DataManager.IsDataChanged()) { var dialog = new MessageDialog("There are unsaved changes to AnimeArchive", "Do you want to save your changes?"); var saveCommand = new UICommand("Save"); var dontSaveCommand = new UICommand("Don't save"); var cancelCommand = new UICommand("Cancel"); dialog.Commands.Add(saveCommand); dialog.Commands.Add(dontSaveCommand); dialog.Commands.Add(cancelCommand); var res = await dialog.ShowAsync(); if (res == cancelCommand) { e.Handled = true; } else if (res == saveCommand) { DataManager.SaveData(); } } deferral.Complete(); }
private async void SystemNavigationManager_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { Deferral deferral = e.GetDeferral(); ContentDialog dlg = new ContentDialog() { Title = "Do you really want to exit the application?", PrimaryButtonText = "Yes", SecondaryButtonText = "No" }; ContentDialogResult result = await dlg.ShowAsync(); if (result == ContentDialogResult.Secondary) { // user cancelled the close operation e.Handled = true; deferral.Complete(); } else { if (Connection != null) { ValueSet message = new ValueSet(); message.Add("InterCommunication", JsonSerializer.Serialize(new Common.InterCommunication() { InterCommunicationType = InterCommunicationType.Exit })); await Connection.SendMessageAsync(message); } e.Handled = false; deferral.Complete(); } }
private async void SystemNavigationManager_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { int closeNum = 1; Deferral deferral = e.GetDeferral(); if (false) { // user cancelled the close operation e.Handled = true; deferral.Complete(); } else { switch (closeNum) { case 0: e.Handled = false; deferral.Complete(); break; case 1: if (ApiInformation.IsApiContractPresent( "Windows.ApplicationModel.FullTrustAppContract", 1, 0)) { await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(); } e.Handled = false; deferral.Complete(); break; } } }
private async void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { var deferral = e.GetDeferral(); e.Handled = await RequireSaveAsync(); deferral.Complete(); }
private async void App_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { var deferral = e.GetDeferral(); await System.Threading.Tasks.Task.Run(() => { AppCommunicator.ExitAllApp(); }); deferral.Complete(); }
private async void CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { var deferral = e.GetDeferral(); e.Handled = !await FileService.IsFileSavedAsync().ConfigureAwait(true); deferral.Complete(); }
// X 버튼 누르시에 할 일을 추가해야함 private void SystemNavigationManager_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { Deferral deferral = e.GetDeferral(); e.Handled = false; deferral.Complete(); }
private async void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { Deferral deferral = e.GetDeferral(); e.Handled = await ViewModel.TabViewManager.TabViewManager.MainTabView.GetUnclosableTabsAsync().CountAsync() > 0 || await ViewModel.TabViewManager.TabViewManager.SolutionExplorerTabView.GetUnclosableTabsAsync().CountAsync() > 0; deferral.Complete(); }
private async void App_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { var deferral = e.GetDeferral(); bool shouldClose = await vm.SaveOnClose(); if (shouldClose == false) { e.Handled = true; } deferral.Complete(); }
private async void SystemNavigationManager_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { Deferral deferral = e.GetDeferral(); if (ApiInformation.IsApiContractPresent( "Windows.ApplicationModel.FullTrustAppContract", 1, 0)) { await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(); } e.Handled = false; deferral.Complete(); }
// close window confirmポップアップを出すメソッド private async void App_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { MainPage mainPage = MainPage.returnInstance(); // ダイアログの中身を定義 ContentDialog dialog = new ContentDialog() { Content = "データが保存されていないままです、本当に終了してもよろしいですか?", Title = "Exit", IsSecondaryButtonEnabled = true, PrimaryButtonText = "保存して終了", SecondaryButtonText = "はい", CloseButtonText = "いいえ" }; bool isDataEdit = mainPage.EditOnce; // データが編集されていなかったらポップアップを出さないようにするために作った if (isDataEdit == false) { Application.Current.Exit(); return; } var windowCloseProcess = e.GetDeferral(); var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { mainPage.saveAllData(); Application.Current.Exit(); } else if (result == ContentDialogResult.Secondary) { Application.Current.Exit(); } else { e.Handled = true; windowCloseProcess.Complete(); } }
private async void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { if (Connection != null) { var def = e.GetDeferral(); await Connection.SendMessageAsync(new ValueSet { { "type", "Close" } }); def.Complete(); } }
private async void CloseHandle(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { Deferral deferral = e.GetDeferral(); ConfirmCloseDialog dlg = new ConfirmCloseDialog(); ContentDialogResult result = await dlg.ShowAsync(); if (result == ContentDialogResult.Secondary) { // user cancelled the close operation e.Handled = true; deferral.Complete(); } else { switch (dlg.Result) { case CloseAction.Terminate: e.Handled = false; deferral.Complete(); break; case CloseAction.Systray: if (ApiInformation.IsApiContractPresent( "Windows.ApplicationModel.FullTrustAppContract", 1, 0)) { // Add User Key string lastUser = (string)ApplicationData.Current.LocalSettings.Values["LAST_USER"]; ApplicationData.Current.LocalSettings.Values.Remove("userInfo"); if (lastUser != null) { string lastUserKey = (string)ApplicationData.Current.LocalSettings.Values[lastUser]; ApplicationDataCompositeValue userInfo = new ApplicationDataCompositeValue { ["name"] = lastUser, ["key"] = lastUserKey }; ApplicationData.Current.LocalSettings.Values["userInfo"] = userInfo; } // Start System Tray await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync("UserInfo"); } e.Handled = false; deferral.Complete(); break; } } }
private async void CloseRequestedTests_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { var deferral = e.GetDeferral(); var dialog = new ContentDialog(); dialog.Title = "Exit"; dialog.Content = "Are you sure you want to exit?"; dialog.PrimaryButtonText = "Yes"; dialog.SecondaryButtonText = "No"; if (await dialog.ShowAsync() != ContentDialogResult.Primary) { //cancel close by handling the event e.Handled = true; } deferral.Complete(); }
private async void App_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { var deferral = e.GetDeferral(); var dialog = new MessageDialog("Are you sure you want to exit?", "Exit"); var confirmCommand = new UICommand("Yes"); var cancelCommand = new UICommand("No"); dialog.Commands.Add(confirmCommand); dialog.Commands.Add(cancelCommand); if (await dialog.ShowAsync() == cancelCommand) { //cancel close by handling the event e.Handled = true; } deferral.Complete(); }
private async void OnCloseRequest(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { var deferral = e.GetDeferral(); e.Handled = true; if (SaveNecessity == true) { try { ContentDialogResult result = await CD_SaveQuery.ShowAsync(); if (result == ContentDialogResult.Primary) { await ViewModel.FileSaveAsync(InkCanvas_GeometrySketch); await ViewModel.AutoSaveAsync(); ViewModel.ProgressRingActive = false; deferral.Complete(); Application.Current.Exit(); } else if (result == ContentDialogResult.Secondary) { ViewModel.ProgressRingActive = false; await ViewModel.AutoSaveAsync(); deferral.Complete(); Application.Current.Exit(); } else { deferral.Complete(); } } catch { } } else { ViewModel.ProgressRingActive = false; await ViewModel.AutoSaveAsync(); deferral.Complete(); Application.Current.Exit(); } }
private void Mgr_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { // get deferral Deferral deferral = e.GetDeferral(); // tell winfrm to exit ValueSet exit = new ValueSet(); exit.Add("exit", null); Send: if (!SendToWin32(exit).Result) { goto Send; } e.Handled = false; deferral.Complete(); }
private async void App_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { // CREDIT: Made possible by the really helpful blog post by Martin Zikmund, go check it out! https://blog.mzikmund.com/2018/09/app-close-confirmation-in-uwp/ // #TODO: Give the user the option to save from this dialog if (App.UnsavedChanges == true) { var deferral = e.GetDeferral(); var dialog = new ExitConfirmationDialog(); await dialog.ShowAsync(); // Check the answer; if no then cancel closing the app if (dialog.Result == ExitConfirmationDialogResult.Cancel || dialog.Result == ExitConfirmationDialogResult.DialogClosed) { // Cancel the closure by setting the Handled-status to true e.Handled = true; } deferral.Complete(); } }
private async void MainPage_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { Deferral Deferral = e.GetDeferral(); if (IsAnyTaskRunning || GeneralTransformer.IsAnyTransformTaskRunning || FullTrustExcutorController.Current.IsNowHasAnyActionExcuting) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_WarningTitle"), Content = Globalization.GetString("QueueDialog_WaitUntilFinish_Content"), PrimaryButtonText = Globalization.GetString("QueueDialog_WaitUntilFinish_PrimaryButton"), CloseButtonText = Globalization.GetString("QueueDialog_WaitUntilFinish_CloseButton") }; if ((await Dialog.ShowAsync().ConfigureAwait(true)) != ContentDialogResult.Primary) { e.Handled = true; } else { IsAnyTaskRunning = false; GeneralTransformer.IsAnyTransformTaskRunning = false; ToastNotificationManager.History.Clear(); } } try { if (!e.Handled && Clipboard.GetContent().Contains(StandardDataFormats.StorageItems)) { Clipboard.Flush(); } } catch { } Deferral.Complete(); }
private async void App_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { // CREDIT: Made possible by the really helpful blog post by Martin Zikmund, go check it out! https://blog.mzikmund.com/2018/09/app-close-confirmation-in-uwp/ // #TODO: Only pop this up when the user actually has unsaved stuff // #TODO: Give the user the option to save from this dialog // #TODO: Migrate to the use of Fluent Framework for the shown dialog var deferral = e.GetDeferral(); var dialog = new ContentDialog(); dialog.Title = "Exit and discard changes?"; dialog.PrimaryButtonText = "Yes"; dialog.SecondaryButtonText = "No"; // Check the answer; if no then cancel closing the app if (await dialog.ShowAsync() == ContentDialogResult.Secondary) { // Cancel the closure by setting the Handled-status to true e.Handled = true; } deferral.Complete(); }
// If we are activated and CloseRequested is called, most likely user tried to close the window with the X in the Titlebar. // - In this case we will minimize the app if we are recording, otherwise we will allow the app to exit // If we are not activated and CloseRequested is called, most likely user tried to close the window with the "Close Window" comand // with the app's icon menu. // - In this case we will always allow the app to exit // These scenarios are arbitrary. Feel free to adjust the behavior to suit the needs of your app. // You can also use a dialog to ask the user if they want to exit the app. For example // CloseAppDialog dialog = new CloseAppDialog(); // var result = await dialog.ShowAsync(); // var minimize = result == ContentDialogResult.Primary; public async void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs args) { var deferral = args.GetDeferral(); // If the ExtendedExecutionForegroundSession is active, don't allow the app to exit unless the user wants it to exit. if (m_session != null && m_isWindowActivated) { args.Handled = true; IList <AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync(); IList <AppResourceGroupInfo> resourceInfos = infos[0].GetResourceGroups(); await resourceInfos[0].StartSuspendAsync(); // minimize the app. App will keep running due to the ExtendedSession } else { args.Handled = false; await ExitApp(); } deferral.Complete(); deferral = null; }
private async void SystemNavigationManager_CloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { Deferral deferral = e.GetDeferral(); //ConfirmCloseDialog dlg = new ConfirmCloseDialog(); //ContentDialogResult result = await dlg.ShowAsync(); //if (result == ContentDialogResult.Secondary) //{ // // user cancelled the close operation // e.Handled = true; // deferral.Complete(); //} //else //{ // switch (dlg.Result) // { // case CloseAction.Terminate: // e.Handled = false; // deferral.Complete(); // break; // case CloseAction.Systray: if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0)) { ApplicationData.Current.LocalSettings.Values["processId"] = Process.GetCurrentProcess().Id; //App.AppServiceConnected += AppServiceConnected; // this was used in newer GlobalHotkey desktop extensions sample to facilitate uwp app processing of hotkeys await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync(); ApplicationData.Current.LocalSettings.Values["systrayComponentRunning"] = true; } e.Handled = false; deferral.Complete(); // break; // } //} }