private async void ExecuteWinDialog(bool reportWinning, Player player, WinningReason winningReason, Move invalidMove) { var yesNoDialogViewModel = new YesNoDialogViewModel(GetWinningOrLoosingMessage(reportWinning, winningReason, invalidMove)); var winningDialog = new YesNoDialog { DataContext = yesNoDialogViewModel }; var dialogResult = await DialogHost.Show(winningDialog, "RootDialog"); if ((bool)dialogResult) { var dialog = new SaveFileDialog() { Filter = "textFiles |*.txt", AddExtension = true, CheckFileExists = false, OverwritePrompt = true, ValidateNames = true, CheckPathExists = true, CreatePrompt = false, Title = Captions.PvB_SaveGameProgressFileDialogTitle }; var result = dialog.ShowDialog(); if (result.HasValue) { if (result.Value) { var fileText = CreateProgressText.FromBoardState(gameService.CurrentBoardState) .AndAppendWinnerAndReason(player, winningReason, invalidMove); File.WriteAllText(dialog.FileName, fileText); } } } yesNoDialogViewModel.Dispose(); }
private async void OnClosing(object sender, CancelEventArgs cancelEventArgs) { var mainWindowViewModel = AssociatedObject.DataContext as IMainWindowViewModel; if (mainWindowViewModel.PreventWindowClosingToAskUser) { cancelEventArgs.Cancel = true; var closingDialogViewModel = new YesNoDialogViewModel(Captions.ClosingDialogMessage); var closingDialog = new YesNoDialog { DataContext = closingDialogViewModel }; var closingDialogResult = await DialogHost.Show(closingDialog, "RootDialog"); if ((bool)closingDialogResult) { var savingDialogViewModel = new YesNoDialogViewModel(Captions.SavingDialogMessage); var savingDialog = new YesNoDialog { DataContext = savingDialogViewModel }; var savingDialogResult = await DialogHost.Show(savingDialog, "RootDialog"); if ((bool)savingDialogResult) { if (mainWindowViewModel.DumpProgressToFile.CanExecute(null)) { mainWindowViewModel.DumpProgressToFile.Execute(null); } } mainWindowViewModel.CloseWindow.Execute(null); } closingDialogViewModel.Dispose(); } }