Exemplo n.º 1
0
        public static MessageDialogResult ShowModalMessageConfirmExternal(this MetroWindow window, string title, string message, MessageDialogStyle style = MessageDialogStyle.Affirmative, MetroDialogSettings settings = null, int?showWidth = null, int?showHeight = null)
        {
            var win = CreateModalExternalWindow(window, showWidth, showHeight);

            settings = settings ?? window.MetroDialogOptions;

            //create the dialog control
            var dialog = new MessageDialogConfirm(window, settings)
            {
                Message      = message,
                Title        = title,
                ButtonStyle  = style,
                DialogBottom = null,
            };

            dialog.PART_AffirmativeButton.Width = dialog.PART_NegativeButton.Width = (showWidth < 1 ? (window.ActualWidth / 2 - 2) : (Convert.ToInt32(showWidth) / 2 - 2));

            SetDialogFontSizes(settings, dialog);

            win.Content = dialog;

            MessageDialogResult result = MessageDialogResult.Affirmative;

            dialog.WaitForButtonPressAsync().ContinueWith(task =>
            {
                result = task.Result;
                win.Invoke(win.Close);
            });

            HandleOverlayOnShow(settings, window);
            win.ShowDialog();
            HandleOverlayOnHide(settings, window);
            return(result);
        }
        private static void SetButtonState(MessageDialogConfirm 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;
            }
            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.Style = md.FindResource("AccentedDialogHighlightedSquareButton") as Style;
                md.PART_NegativeButton.Style    = md.FindResource("AccentedDialogHighlightedSquareButton") as Style;
                break;
            }
        }