/// <summary> /// Static constructor /// </summary> static DialogTask() { // Create a special 'Killed' dialog task by creating and running a normal dialog task. using (var cts = new CancellationTokenSource()) { Killed = new DialogTask(cts.Token); Killed.Start(); } }
private DialogTask Show ( object viewModel, IViewProvider viewProvider, IEnumerable <ButtonConfiguration> buttonConfigurations, DialogDisplayLocation displayLocation, DialogDisplayBehavior displayBehavior, DialogOptions dialogOptions, CancellationToken cancellationToken ) { if (cancellationToken.IsCancellationRequested) { return(DialogTask.Killed); } DialogTask dialogTask = null; Application.Current.Dispatcher.Invoke(() => { var view = viewProvider.GetViewInstance(viewModel); // Find the matching handler for the display location. var dialogHandler = _dialogHandlers.GetDialogHandler(displayLocation); // Tell it to show the content. dialogTask = dialogHandler.ShowView(view, buttonConfigurations, displayBehavior, dialogOptions, cancellationToken); }); if (dialogTask is null) { return(null); } if (cancellationToken.IsCancellationRequested) { return(DialogTask.Killed); } dialogTask.Start(); return(dialogTask); }
public Dialog ( Visual contentView, ICollection <Button> buttons, Action <DialogResult> closeCallback, DialogOptions options, CancellationToken externalCancellationToken ) { // Save parameters. _closeCallback = closeCallback; this.ContentView = contentView; this.Buttons = buttons; this.Options = options; this.ExternalCancellationToken = externalCancellationToken; // Initialize fields. _cancellationTokenSource = new CancellationTokenSource(); _dialogTaskFactory = new DialogTaskFactory(); this.DialogTask = _dialogTaskFactory.Create(closeCallback, _cancellationTokenSource.Token); }