示例#1
0
 private static Task HandleOverlayOnShow(MetroDialogSettings settings, MetroWindow window)
 {
     return(Task.Factory.StartNew(() =>
     {
         window.Invoke(() =>
         {
             var isCloseButtonEnabled = window.ShowDialogsOverTitleBar || settings == null || settings.OwnerCanCloseWithDialog;
             window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.Box(isCloseButtonEnabled));
         });
     })
            .ContinueWith(task =>
     {
         return window.Invoke(() =>
         {
             if (!window.metroActiveDialogContainer.Children.OfType <BaseMetroDialog>().Any())
             {
                 return (settings == null || settings.AnimateShow ? window.ShowOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(window.ShowOverlay))));
             }
             else
             {
                 var tcs = new System.Threading.Tasks.TaskCompletionSource <object>();
                 tcs.SetResult(null);
                 return tcs.Task;
             }
         });
     })
            .Unwrap());
 }
示例#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);
        }
示例#3
0
        /// <summary>
        /// Creates a <see cref="CustomMessageDialog"/> inside of the current window.
        /// </summary>
        /// <param name="window">The MetroWindow</param>
        /// <param name="title">The title of the <see cref="CustomMessageDialog"/>.</param>
        /// <param name="message">The message contained within the <see cref="CustomMessageDialog"/>.</param>
        /// <param name="style">The type of buttons to use.</param>
        /// <param name="settings">Optional settings that override the global metro dialog settings.</param>
        /// <returns>A task promising the result of which button was pressed.</returns>
        public static Task <MessageDialogResult> ShowCustomMessageAsync(
            this MetroWindow window, string title, object message, MessageDialogStyle style = MessageDialogStyle.Affirmative, MetroDialogSettings settings = null)
        {
            settings = settings ?? window.MetroDialogOptions;
            var dialog = new CustomMessageDialog(window, settings)
            {
                Message     = message,
                Title       = title,
                ButtonStyle = style
            };

            var tcs = new TaskCompletionSource <MessageDialogResult>();

            dialog.WaitForButtonPressAsync().ContinueWith(async task =>
            {
                await window.Invoke(async() =>
                {
                    await window.HideMetroDialogAsync(dialog);
                    // The focus may have changed and altered the command-routing path, so suggest that command conditions be re-evaluated.
                    // Note that this may no longer necessary since making the "current document" content control
                    // focusable (which fixed a bunch of command condition re-evaluation issues).
                    CommandManager.InvalidateRequerySuggested();
                });
                tcs.TrySetResult(task.Result);
            });

            window.ShowMetroDialogAsync(dialog, settings ?? window.MetroDialogOptions);

            return(tcs.Task);
        }