Exemplo n.º 1
0
        /// <summary>
        /// Creates a ProgressDialog inside of the current window.
        /// </summary>
        /// <param name="window">The MetroWindow</param>
        /// <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> >(() =>
                {
                    var dialog = new ProgressDialog(window)
                    {
                        Message = message,
                        Title = title,
                        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(a =>
                            {
                                return (Task)window.Dispatcher.Invoke(new Func <Task>(() =>
                                {
                                    window.SizeChanged -= sizeHandler;

                                    window.RemoveDialog(dialog);

                                    return HandleOverlayOnHide(settings, window);
                                }));
                            }).Unwrap();
                        });
                    });
                })));
            }).Unwrap());
        }
        /// <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());
        }
        /// <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.IsCancelable = isCancelable;
                        dialog.NegativeButtonText = window.MetroDialogOptions.NegativeButtonText;
                        SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, title, 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();
        }
Exemplo n.º 4
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();
        }
Exemplo 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());
        }