Esempio n. 1
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);
        }
Esempio n. 2
0
        private static void SetButtonState(CustomMessageDialog md)
        {
            if (md.PART_AffirmativeButton == null)
            {
                return;
            }

            switch (md.ButtonStyle)
            {
            case MessageDialogStyle.Affirmative:
            {
                md.PART_AffirmativeButton.Visibility     = Visibility.Visible;
                md.PART_NegativeButton.Visibility        = Visibility.Collapsed;
                md.PART_FirstAuxiliaryButton.Visibility  = Visibility.Collapsed;
                md.PART_SecondAuxiliaryButton.Visibility = Visibility.Collapsed;
            }
            break;

            case MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary:
            case MessageDialogStyle.AffirmativeAndNegativeAndDoubleAuxiliary:
            case MessageDialogStyle.AffirmativeAndNegative:
            {
                md.PART_AffirmativeButton.Visibility = Visibility.Visible;
                md.PART_NegativeButton.Visibility    = Visibility.Visible;

                if (md.ButtonStyle == MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary || md.ButtonStyle == MessageDialogStyle.AffirmativeAndNegativeAndDoubleAuxiliary)
                {
                    md.PART_FirstAuxiliaryButton.Visibility = Visibility.Visible;
                }

                if (md.ButtonStyle == MessageDialogStyle.AffirmativeAndNegativeAndDoubleAuxiliary)
                {
                    md.PART_SecondAuxiliaryButton.Visibility = Visibility.Visible;
                }
            }
            break;
            }

            md.AffirmativeButtonText     = md.DialogSettings.AffirmativeButtonText;
            md.NegativeButtonText        = md.DialogSettings.NegativeButtonText;
            md.FirstAuxiliaryButtonText  = md.DialogSettings.FirstAuxiliaryButtonText;
            md.SecondAuxiliaryButtonText = md.DialogSettings.SecondAuxiliaryButtonText;

            switch (md.DialogSettings.ColorScheme)
            {
            case MetroDialogColorScheme.Accented:
                md.PART_AffirmativeButton.SetResourceReference(StyleProperty, "AccentedDialogHighlightedSquareButton");
                md.PART_NegativeButton.SetResourceReference(StyleProperty, "AccentedDialogHighlightedSquareButton");
                md.PART_FirstAuxiliaryButton.SetResourceReference(StyleProperty, "AccentedDialogHighlightedSquareButton");
                md.PART_SecondAuxiliaryButton.SetResourceReference(StyleProperty, "AccentedDialogHighlightedSquareButton");
                break;
            }
        }