public async Task ExportAsync(string name, Document document, IExporter exporter, IRenderer renderer) { if (await dialogService.ConfirmAsync(LocalizationManager.GetString("Export_EmailConfirm"))) { var extension = exporter.Extensions.FirstOrDefault(); if (extension == null) { throw new InvalidOperationException("The exporter needs to specify at least one file extension."); } var buffer = await SerializeAsync(document, exporter, renderer); var downloadUri = await UploadAsync(name, extension, buffer); var subj = LocalizationManager.GetFormattedString("Export_EmailSubject"); var body = LocalizationManager.GetFormattedString("Export_EmailBody", downloadUri); var message = new EmailMessage { Subject = subj, Body = body }; await EmailManager.ShowComposeNewEmailAsync(message); } }
private async void ShowConfirmClicked(object sender, EventArgs e) { var isYes = await _dialogService.ConfirmAsync("Confirm?", "content"); if (isYes) { await _dialogService.AlertAsync("", "Yes"); } }
public ProjectsViewModel(IProjectService projects, IAppStateService state, IDialogService dialog) { _projects = projects; _state = state; _dialog = dialog; _state.KeysChanged += async(s, e) => { await LoadAsync(); }; this.ShowCreate = new RelayCommand(() => { IsCreating = true; }); this.SelectProject = new RelayCommand <Project>((project) => { if (project == null) { return; } _state.CurrentProject = project; _state.SetCurrentPackage(null); ApplicationData.Current.LocalSettings.Values["LastProject"] = _state.CurrentProject.Name; }); this.CreateProject = new RelayCommand <string>(async(project) => { if (string.IsNullOrWhiteSpace(project)) { return; } var newProject = await _projects.CreateProjectAsync(project); ProjectsList.Add(newProject); CurrentProject = newProject; IsCreating = false; }); this.ManageProjects = new RelayCommand(async() => { await _dialog.OpenAsync(DialogKeys.ManageProjects, this); }); this.DeleteProject = new RelayCommand <Project>(async(project) => { Debug.WriteLine($"Delete {project.Name}"); var confirm = await _dialog.ConfirmAsync("Confirm", $"Are you sure you want to delete {project.Name}?", "Yes", "No"); if (!confirm) { return; } await _projects.DeleteProjectAsync(project.Id); if (CurrentProject.Id == project.Id) { CurrentProject = null; } ProjectsList.Remove(project); }); }
public async Task HandleExternalLinkAsync(string url) { if (string.IsNullOrWhiteSpace(url) || !Uri.TryCreate(url, UriKind.Absolute, out var uri)) { return; } var title = "External link"; var msg = $"Do you want to leave the app to visit {uri.Host}?"; var confirmed = await _dialog.ConfirmAsync(title, msg, "Yes", "No"); if (confirmed) { await _browser.ShowInBrowserAsync(uri, true); } }
/// <summary> /// This method provides a wrapper for any method which takes no parameters without return type AND /// is going to be called in a command. /// </summary> /// <param name="func">The function / method that is going to be called in this method.</param> /// <param name="invokingSettings">Settings for invoking</param> /// <returns></returns> protected virtual async Task InvokeAsync(Func <Task> func, InvokingSettings invokingSettings = null) { InvokingSettings settings = invokingSettings ?? new InvokingSettings(); try { if (settings.Confirmation != null) { var confirmation = settings.Confirmation; var result = await DialogService.ConfirmAsync( confirmation.Message, confirmation.Title, confirmation.OkButtonLabel, confirmation.CancelButtonLabel, confirmation.CancellationToken); if (result == false) { return; } } DialogService.ShowLoading(settings.BusyMessage); await func(); DialogService.HideLoading(settings.BusyMessage); if (settings.Info != null) { var info = settings.Info; await DialogService.ShowAlertAsync( info.Message, info.Title, info.ButtonLabel); } if (settings.Callback != null) { await settings.Callback(); } } catch (Exception) { DialogService.HideLoading(settings.BusyMessage); throw; } }