/// <inheritdoc /> public Task <UserInputResult> GetUserInputAsync(string title, string message, UserInputOption options, UserInputResult defaultResult) { var scheduler = TaskScheduler.FromCurrentSynchronizationContext(); return(Task.Factory.StartNew( () => { MessageBoxResult result = MessageBox.Show(Application.Current.MainWindow, message, title, (MessageBoxButton)options, MessageBoxImage.None, (MessageBoxResult)defaultResult); return (UserInputResult)result; }, CancellationToken.None, TaskCreationOptions.None, scheduler)); }
/// <inheritdoc /> public async Task <UserInputResult> GetUserInputAsync(string title, string message, UserInputOption options, UserInputResult defaultResult) { var resources = this.GetResourceLoader(); MessageDialog dialog = new MessageDialog(message, title); switch (options) { case UserInputOption.Ok: dialog.Commands.Add(new UICommand(resources.GetString("OK")) { Id = UserInputResult.Ok }); break; case UserInputOption.OkCancel: dialog.Commands.Add(new UICommand(resources.GetString("OK")) { Id = UserInputResult.Ok }); dialog.Commands.Add(new UICommand(resources.GetString("Cancel")) { Id = UserInputResult.Cancel }); dialog.CancelCommandIndex = 1; if (defaultResult == UserInputResult.Ok) { dialog.DefaultCommandIndex = 0; } else { dialog.DefaultCommandIndex = 1; } break; case UserInputOption.YesNo: dialog.Commands.Add(new UICommand(resources.GetString("Yes")) { Id = UserInputResult.Yes }); dialog.Commands.Add(new UICommand(resources.GetString("No")) { Id = UserInputResult.No }); dialog.CancelCommandIndex = 1; if (defaultResult == UserInputResult.Yes) { dialog.DefaultCommandIndex = 0; } else { dialog.DefaultCommandIndex = 1; } break; case UserInputOption.YesNoCancel: dialog.Commands.Add(new UICommand(resources.GetString("Yes")) { Id = UserInputResult.Yes }); dialog.Commands.Add(new UICommand(resources.GetString("No")) { Id = UserInputResult.No }); dialog.Commands.Add(new UICommand(resources.GetString("Cancel")) { Id = UserInputResult.Cancel }); dialog.CancelCommandIndex = 2; switch (defaultResult) { case UserInputResult.Yes: dialog.DefaultCommandIndex = 0; break; case UserInputResult.No: dialog.DefaultCommandIndex = 1; break; default: dialog.DefaultCommandIndex = 2; break; } break; } IUICommand command = await dialog.ShowAsync(); return((UserInputResult)command.Id); }