Esempio n. 1
0
        /// <summary>
        /// Shows the <paramref name="contentView"/>.
        /// </summary>
        /// <param name="contentView"> The <see cref="Visual"/> to show. </param>
        /// <param name="buttonConfigurations"> The configurations for <see cref="Models.Button"/>s to show. </param>
        /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> for showing the <paramref name="contentView"/>. </param>
        /// <param name="dialogOptions"> <see cref="DialogOptions"/> for the new <see cref="Dialog"/>. </param>
        /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
        /// <returns> The <see cref="DialogTask"/> used to interact and await the shown view. </returns>
        internal DialogTask ShowView
        (
            Visual contentView,
            IEnumerable <ButtonConfiguration> buttonConfigurations,
            DialogDisplayBehavior displayBehavior,
            DialogOptions dialogOptions,
            CancellationToken cancellationToken
        )
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(DialogTask.Killed);
            }

            // If necessary, handle the currently displayed view.
            switch (displayBehavior)
            {
            case DialogDisplayBehavior.Show:
                break;

            case DialogDisplayBehavior.Override:
                this.RemoveTopMostView(DialogResult.Killed);
                break;
            }

            // Create buttons from the configuration.
            var buttons = buttonConfigurations
                          .Select(configuration => new Models.Button(configuration, this.Revoke))
                          .ToList()
            ;

            // Create a new dialog.
            var dialog = new Dialog
                         (
                contentView: contentView,
                buttons: buttons,
                closeCallback: this.Revoke,
                options: dialogOptions,
                externalCancellationToken: cancellationToken
                         );

            if (cancellationToken.IsCancellationRequested)
            {
                return(DialogTask.Killed);
            }

            // Save it.
            _dialogs.Push(dialog);

            // Show it.
            this.ShowView();

            // Return it.
            return(dialog.DialogTask);
        }
Esempio n. 2
0
 /// <summary>
 /// Shows a message dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="messageModels"> A collection of <see cref="MessageDialogModel"/>s for the dialog. </param>
 /// <param name="buttons"> The <see cref="DialogButtons"/> to display. Default is <see cref="DialogButtons.Ok"/>. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowMessage
 (
     this IDialogManager dialogManager,
     ICollection <MessageDialogModel> messageModels,
     DialogButtons buttons = DialogButtons.Ok,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowMessage(messageModels, DefaultButtonConfigurations.GetConfiguration(buttons), displayLocation, displayBehavior, dialogOptions, cancellationToken);
Esempio n. 3
0
 /// <summary>
 /// Shows a message dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="messageModel"> The <see cref="MessageDialogModel"/> of the dialog. </param>
 /// <param name="buttons"> The <see cref="DialogButtons"/> to display. Default is <see cref="DialogButtons.Ok"/>. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowMessage
 (
     this IDialogManager dialogManager,
     MessageDialogModel messageModel,
     DialogButtons buttons = DialogButtons.Ok,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowMessage(new[] { messageModel }, buttons, displayLocation, displayBehavior, dialogOptions, cancellationToken);
Esempio n. 4
0
 /// <summary>
 /// Shows an exception dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="title"> The title of the dialog. </param>
 /// <param name="message"> The message of the dialog. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowException
 (
     this IDialogManager dialogManager,
     string title   = null,
     string message = null,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowExceptions(new Exception[0], title, message, displayLocation, displayBehavior, dialogOptions, cancellationToken);
Esempio n. 5
0
 /// <summary>
 /// Shows a warning dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="messageModels"> A collection of <see cref="MessageDialogModel"/>s for the dialog. </param>
 /// <param name="buttonConfigurations"> A collection of custom <see cref="ButtonConfiguration"/> used to display buttons. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowWarning
 (
     this IDialogManager dialogManager,
     ICollection <MessageDialogModel> messageModels,
     IEnumerable <ButtonConfiguration> buttonConfigurations,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowMessage(new WarningDialogViewModel(messageModels), buttonConfigurations, displayLocation, displayBehavior, dialogOptions, cancellationToken);
 /// <inheritdoc />
 public DialogTask ShowContent
 (
     object viewModel,
     IEnumerable <ButtonConfiguration> buttonConfigurations,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.HideTransparencyToggle,
     CancellationToken cancellationToken   = default
 )
 {
     return(this.Show(viewModel, _wrappingViewProvider, buttonConfigurations, displayLocation, displayBehavior, dialogOptions, cancellationToken));
 }
Esempio n. 7
0
 /// <summary>
 /// Shows an exception dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="exception"> The <see cref="Exception"/> of the dialog. If this is an <see cref="AggregateException"/>, then the <see cref="AggregateException.InnerExceptions"/> collection will be used. </param>
 /// <param name="title"> The title of the dialog. </param>
 /// <param name="message"> The message of the dialog. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowException
 (
     this IDialogManager dialogManager,
     Exception exception,
     string title   = null,
     string message = null,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowExceptions(exception is AggregateException aggregateException ? aggregateException.InnerExceptions.ToArray() : new[] { exception }, title, message, displayLocation, displayBehavior, dialogOptions, cancellationToken);
Esempio n. 8
0
 /// <summary>
 /// Shows a message dialog.
 /// </summary>
 /// <param name="dialogManager"> The extended <see cref="IDialogManager"/>. </param>
 /// <param name="title"> The title of the dialog. </param>
 /// <param name="message"> The message of the dialog. </param>
 /// <param name="contentViewModel"> The inner content (view model) of the dialog. </param>
 /// <param name="buttons"> The <see cref="DialogButtons"/> to display. Default is <see cref="DialogButtons.Ok"/>. </param>
 /// <param name="displayLocation"> The <see cref="DialogDisplayLocation"/> of the dialog. Default is <see cref="DialogDisplayLocation.Window"/>. </param>
 /// <param name="displayBehavior"> The <see cref="DialogDisplayBehavior"/> of the dialog. Default is <see cref="DialogDisplayBehavior.Show"/>. </param>
 /// <param name="dialogOptions"> The <see cref="DialogOptions"/> of the dialog. Default is <see cref="DialogOptions.None"/>. </param>
 /// <param name="cancellationToken"> An external <see cref="CancellationToken"/> used to cancel the dialog. </param>
 /// <returns> An awaitable <see cref="DialogTask"/>. </returns>
 public static DialogTask ShowMessage
 (
     this IDialogManager dialogManager,
     string title            = null,
     string message          = null,
     object contentViewModel = null,
     DialogButtons buttons   = DialogButtons.Ok,
     DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
     DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
     DialogOptions dialogOptions           = DialogOptions.None,
     CancellationToken cancellationToken   = default
 )
 => dialogManager.ShowMessage(new MessageDialogModel(identifier: null, title: title, message: message, contentViewModel: contentViewModel), buttons, displayLocation, displayBehavior, dialogOptions, cancellationToken);
        /// <inheritdoc />
        public DialogTask ShowExceptions
        (
            ICollection <Exception> exceptions,
            string title   = null,
            string message = null,
            DialogDisplayLocation displayLocation = DialogDisplayLocation.Window,
            DialogDisplayBehavior displayBehavior = DialogDisplayBehavior.Show,
            DialogOptions dialogOptions           = DialogOptions.None,
            CancellationToken cancellationToken   = default
        )
        {
            var viewModel            = new ExceptionDialogViewModel(title, message, exceptions);
            var buttonConfigurations = new[] { DefaultButtonConfigurations.OkButtonConfiguration };

            return(this.Show(viewModel, _dialogAssemblyViewProvider, buttonConfigurations, displayLocation, displayBehavior, dialogOptions, cancellationToken));
        }
        /// <inheritdoc />
        public DialogTask ShowMessage
        (
            MessageDialogViewModel viewModel,
            IEnumerable <ButtonConfiguration> buttonConfigurations,
            DialogDisplayLocation displayLocation,
            DialogDisplayBehavior displayBehavior,
            DialogOptions dialogOptions,
            CancellationToken cancellationToken = default
        )
        {
            // Try to resolve the content views of all message models if necessary.
            foreach (var messageDialogModel in viewModel.MessageModels.Where(model => model.ContentViewModel != null))
            {
                messageDialogModel.ContentView = _wrappingViewProvider.GetViewInstance(messageDialogModel.ContentViewModel);
            }

            return(this.Show(viewModel, _dialogAssemblyViewProvider, buttonConfigurations, displayLocation, displayBehavior, dialogOptions, cancellationToken));
        }
        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);
        }