An internal control that represents a message dialog. Please use MetroWindow.ShowMessage instead!
Inheritance: BaseMetroDialog
        internal ProgressDialogController(ProgressDialog dialog, Func<Task> closeCallBack)
        {
            this.WrappedDialog = dialog;
            this.CloseCallback = closeCallBack;

            this.IsOpen = dialog.IsVisible;

            this.WrappedDialog.Invoke(() => { this.WrappedDialog.PART_NegativeButton.Click += this.PART_NegativeButton_Click; });

            dialog.CancellationToken.Register(() => { this.PART_NegativeButton_Click(null, new RoutedEventArgs()); });
        }
        internal ProgressDialogController(ProgressDialog dialog, Func<Task> closeCallBack)
        {
            WrappedDialog = dialog;
            CloseCallback = closeCallBack;

            IsOpen = dialog.IsVisible;

            WrappedDialog.PART_NegativeButton.Dispatcher.Invoke(new Action(() => {
                WrappedDialog.PART_NegativeButton.Click += PART_NegativeButton_Click;
            }));
        }
        internal ProgressDialogController(ProgressDialog dialog, Func<Task> closeCallBack)
        {
            WrappedDialog = dialog;
            CloseCallback = closeCallBack;

            IsOpen = dialog.IsVisible;

            WrappedDialog.PART_NegativeButton.Dispatcher.Invoke(new Action(() => {
                WrappedDialog.PART_NegativeButton.Click += PART_NegativeButton_Click;
            }));

            dialog.CancellationToken.Register(() =>
            {
                PART_NegativeButton_Click(null, new RoutedEventArgs());
            });
        }
        /// <summary>
        /// Creates a ProgressDialog inside of the current window.
        /// </summary>
        /// <param name="title">The title of the ProgressDialog.</param>
        /// <param name="message">The message within the ProgressDialog.</param>
        /// <param name="isCancelable">Determines if the cancel button is visible.</param>
        /// <returns>A task promising the instance of ProgressDialogController for this operation.</returns>
        public static Task<ProgressDialogController> ShowProgressAsync(this MetroWindow window, string title, string message, bool isCancelable = false)
        {
            window.Dispatcher.VerifyAccess();

            return window.ShowOverlayAsync().ContinueWith(z =>
            {
                return ((Task<ProgressDialogController>)window.Dispatcher.Invoke(new Func<Task<ProgressDialogController>>(() =>
                    {
                        //create the dialog control
                        ProgressDialog dialog = new ProgressDialog(window);
                        dialog.Message = message;
                        dialog.Title = title;
                        dialog.IsCancelable = isCancelable;
                        dialog.NegativeButtonText = window.MetroDialogOptions.NegativeButtonText;
                        SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                        dialog.SizeChangedHandler = sizeHandler;

                        return dialog.WaitForLoadAsync().ContinueWith(x =>
                        {
                            return new ProgressDialogController(dialog, () =>
                            {
                                dialog.OnClose();

                                return (Task)window.Dispatcher.Invoke(new Func<Task>(() =>
                                {
                                    window.SizeChanged -= sizeHandler;

                                    window.messageDialogContainer.Children.Remove(dialog); //remove the dialog from the container

                                    return window.HideOverlayAsync();
                                    //window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect
                                }));
                            });
                        });
                    })));
            }).Unwrap();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a ProgressDialog inside of the current window.
        /// </summary>
        /// <param name="title">The title of the ProgressDialog.</param>
        /// <param name="message">The message within the ProgressDialog.</param>
        /// <param name="isCancelable">Determines if the cancel button is visible.</param>
        /// <param name="settings">Optional Settings that override the global metro dialog settings.</param>
        /// <returns>A task promising the instance of ProgressDialogController for this operation.</returns>
        public static Task<ProgressDialogController> ShowProgressAsync(this MetroWindow window, string title, string message, bool isCancelable = false, MetroDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();

            return HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return ((Task<ProgressDialogController>)window.Dispatcher.Invoke(new Func<Task<ProgressDialogController>>(() =>
                    {
                        //create the dialog control
                        ProgressDialog dialog = new ProgressDialog(window);
                        dialog.Message = message;
                        dialog.Title = title;
                        dialog.IsCancelable = isCancelable;

                        if (settings == null)
                            settings = window.MetroDialogOptions;

                        dialog.NegativeButtonText = settings.NegativeButtonText;

                        SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                        dialog.SizeChangedHandler = sizeHandler;

                        return dialog.WaitForLoadAsync().ContinueWith(x =>
                        {
                            if (DialogOpened != null)
                            {
                                window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs()
                                {
                                })));
                            }

                            return new ProgressDialogController(dialog, () =>
                            {
                                dialog.OnClose();

                                if (DialogClosed != null)
                                {
                                    window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()
                                    {
                                    })));
                                }

                                Task closingTask = (Task)window.Dispatcher.Invoke(new Func<Task>(() => dialog._WaitForCloseAsync()));
                                return closingTask.ContinueWith<Task>(a =>
                                {
                                    return (Task)window.Dispatcher.Invoke(new Func<Task>(() =>
                                    {
                                        window.SizeChanged -= sizeHandler;

                                        window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container

                                        return HandleOverlayOnHide(settings, window);
                                        //window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect
                                    }));
                                }).Unwrap();
                            });
                        });
                    })));
            }).Unwrap();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a ProgressDialog inside of the current window.
        /// </summary>
        /// <param name="title">The title of the ProgressDialog.</param>
        /// <param name="message">The message within the ProgressDialog.</param>
        /// <param name="isCancelable">Determines if the cancel button is visible.</param>
        /// <param name="settings">Optional Settings that override the global metro dialog settings.</param>
        /// <returns>A task promising the instance of ProgressDialogController for this operation.</returns>
        public static Task <ProgressDialogController> ShowProgressAsync(this MetroWindow window, string title, string message, bool isCancelable = false, MetroDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();

            return(HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return ((Task <ProgressDialogController>)window.Dispatcher.Invoke(new Func <Task <ProgressDialogController> >(() =>
                {
                    //create the dialog control
                    ProgressDialog dialog = new ProgressDialog(window);
                    dialog.Message = message;
                    dialog.Title = title;
                    dialog.IsCancelable = isCancelable;

                    if (settings == null)
                    {
                        settings = window.MetroDialogOptions;
                    }

                    dialog.NegativeButtonText = settings.NegativeButtonText;

                    SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                    dialog.SizeChangedHandler = sizeHandler;

                    return dialog.WaitForLoadAsync().ContinueWith(x =>
                    {
                        if (DialogOpened != null)
                        {
                            window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs()
                            {
                            })));
                        }

                        return new ProgressDialogController(dialog, () =>
                        {
                            dialog.OnClose();

                            if (DialogClosed != null)
                            {
                                window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()
                                {
                                })));
                            }

                            Task closingTask = (Task)window.Dispatcher.Invoke(new Func <Task>(() => dialog._WaitForCloseAsync()));
                            return closingTask.ContinueWith <Task>(a =>
                            {
                                return (Task)window.Dispatcher.Invoke(new Func <Task>(() =>
                                {
                                    window.SizeChanged -= sizeHandler;

                                    window.metroDialogContainer.Children.Remove(dialog);     //remove the dialog from the container

                                    return HandleOverlayOnHide(settings, window);
                                    //window.overlayBox.Visibility = System.Windows.Visibility.Hidden; //deactive the overlay effect
                                }));
                            }).Unwrap();
                        });
                    });
                })));
            }).Unwrap());
        }