Ejemplo n.º 1
0
        /// <summary>
        /// Hides a visible Metro Dialog instance.
        /// </summary>
        /// <param name="window">The window with the dialog that is visible.</param>
        /// <param name="dialog">The dialog instance to hide.</param>
        /// <returns>A task representing the operation.</returns>
        /// <exception cref="InvalidOperationException">
        /// The <paramref name="dialog"/> is not visible in the window.
        /// This happens if <see cref="ShowMetroDialogAsync"/> hasn't been called before.
        /// </exception>
        public static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog)
        {
            window.Dispatcher.VerifyAccess();
            if (!window.metroDialogContainer.Children.Contains(dialog))
            {
                throw new InvalidOperationException("The provided dialog is not visible in the specified window.");
            }

            window.SizeChanged -= dialog.SizeChangedHandler;

            dialog.OnClose();

            Task closingTask = (Task)window.Dispatcher.Invoke(new Func <Task>(() => dialog._WaitForCloseAsync()));

            return(closingTask.ContinueWith <Task>(a =>
            {
                if (DialogClosed != null)
                {
                    window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs()
                    {
                    })));
                }

                return (Task)window.Dispatcher.Invoke(new Func <Task>(() =>
                {
                    window.metroDialogContainer.Children.Remove(dialog); //remove the dialog from the container

                    return window.HideOverlayAsync();
                }));
            }).Unwrap());
        }
Ejemplo n.º 2
0
        private static Task HandleOverlayOnHide(MetroDialogSettings settings, MetroWindow window)
        {
            Task result = null;

            if (!window.metroActiveDialogContainer.Children.OfType <BaseMetroDialog>().Any())
            {
                result = (settings == null || settings.AnimateHide ? window.HideOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(window.HideOverlay))));
            }
            else
            {
                var tcs = new System.Threading.Tasks.TaskCompletionSource <object>();
                tcs.SetResult(null);
                result = tcs.Task;
            }

            result.ContinueWith(task =>
            {
                window.Invoke(() =>
                {
                    if (window.metroActiveDialogContainer.Children.Count == 0)
                    {
                        window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.TrueBox);
                        window.RestoreFocus();
                    }
                    else
                    {
                        var onTopShownDialogSettings = window.metroActiveDialogContainer.Children.OfType <BaseMetroDialog>().LastOrDefault()?.DialogSettings;
                        var isCloseButtonEnabled     = window.ShowDialogsOverTitleBar || onTopShownDialogSettings == null || onTopShownDialogSettings.OwnerCanCloseWithDialog;
                        window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.Box(isCloseButtonEnabled));
                    }
                });
            });

            return(result);
        }
Ejemplo n.º 3
0
 private static Task HandleOverlayOnHide(MetroDialogSettings settings, MetroWindow window)
 {
     if (!window.metroActiveDialogContainer.Children.OfType <BaseMetroDialog>().Any())
     {
         return(settings == null || settings.AnimateHide ? window.HideOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(window.HideOverlay))));
     }
     else
     {
         var tcs = new System.Threading.Tasks.TaskCompletionSource <object>();
         tcs.SetResult(null);
         return(tcs.Task);
     }
 }
Ejemplo n.º 4
0
 private static Task HandleOverlayOnHide(MetroDialogSettings settings, MetroWindow window)
 {
     if (window.metroActiveDialogContainer.Children.OfType <BaseMetroDialog>().Any <BaseMetroDialog>())
     {
         TaskCompletionSource <object> taskCompletionSource = new TaskCompletionSource <object>();
         taskCompletionSource.SetResult(null);
         return(taskCompletionSource.Task);
     }
     if (settings == null || settings.AnimateHide)
     {
         return(window.HideOverlayAsync());
     }
     return(Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(window.HideOverlay))));
 }
        /// <summary>
        /// Hides a visible Metro Dialog instance.
        /// </summary>
        /// <param name="window">The window with the dialog that is visible.</param>
        /// <param name="dialog">The dialog instance to hide.</param>
        /// <returns>A task representing the operation.</returns>
        /// <exception cref="InvalidOperationException">
        /// The <paramref name="dialog"/> is not visible in the window.
        /// This happens if <see cref="ShowMetroDialogAsync"/> hasn't been called before.
        /// </exception>
        public static Task HideMetroDialogAsync(this MetroWindow window, BaseMetroDialog dialog)
        {
            window.Dispatcher.VerifyAccess();
            if (!window.messageDialogContainer.Children.Contains(dialog))
            {
                throw new InvalidOperationException("The provided dialog is not visible in the specified window.");
            }

            window.SizeChanged -= dialog.SizeChangedHandler;

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

            return(window.HideOverlayAsync());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 隐藏遮罩
        /// </summary>
        public static async Task HideOverlayAsync()
        {
            MetroWindow currentView = Application.Current.MainWindow as MetroWindow;

            if (currentView == null && _Current != null)
            {
                ViewAware viewAware = (ViewAware)_Current;
                currentView = (MetroWindow)viewAware.GetView();
            }
            else if (currentView == null)
            {
                return;
            }
            else
            {
                return;
            }

            await currentView.HideOverlayAsync();
        }
        /// <summary>
        /// Creates a MessageDialog inside of the current window.
        /// </summary>
        /// <param name="title">The title of the MessageDialog.</param>
        /// <param name="message">The message contained within the MessageDialog.</param>
        /// <param name="style">The type of buttons to use.</param>
        /// <returns>A task promising the result of which button was pressed.</returns>
        public static Task <MessageDialogResult> ShowMessageAsync(this MetroWindow window, string title, string message, MessageDialogStyle style = MessageDialogStyle.Affirmative)
        {
            window.Dispatcher.VerifyAccess();
            return(window.ShowOverlayAsync().ContinueWith(z =>
            {
                return (Task <MessageDialogResult>)window.Dispatcher.Invoke(new Func <Task <MessageDialogResult> >(() =>
                {
                    //create the dialog control
                    MessageDialog dialog = new MessageDialog(window);
                    dialog.Message = message;
                    dialog.Title = title;
                    dialog.ButtonStyle = style;

                    dialog.AffirmativeButtonText = window.MetroDialogOptions.AffirmativeButtonText;
                    dialog.NegativeButtonText = window.MetroDialogOptions.NegativeButtonText;

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

                    return dialog.WaitForLoadAsync().ContinueWith(x =>
                    {
                        return dialog.WaitForButtonPressAsync().ContinueWith(y =>
                        {
                            //once a button as been clicked, begin removing the 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
                            }))).ContinueWith(y3 => y).Unwrap();
                        }).Unwrap();
                    }).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());
        }
Ejemplo n.º 9
0
 private static Task HandleOverlayOnHide(MetroDialogSettings settings, MetroWindow window)
 {
     return (settings == null || settings.UseAnimations ? window.HideOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(() => window.HideOverlay()))));
 }
Ejemplo n.º 10
0
 private static Task HandleOverlayOnHide(MetroDialogSettings settings, MetroWindow window)
 {
     return(settings == null || settings.AnimateHide ? window.HideOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(window.HideOverlay))));
 }