Пример #1
0
        public MessageDialogResult ShowDialog(string message, ColorScheme colorScheme = null, Window owner = null, string title = "Dialog", MessageDialogButtonDisplay buttonDisplay = MessageDialogButtonDisplay.Auto,
                                              MessageDialogImage image  = MessageDialogImage.None, MessageDialogResult defaultButton = MessageDialogResult.Cancel,
                                              string customOkButtonText = null, string customCancelButtonText = null, string customDiscardButtonText = null,
                                              string extraButton1Text   = null, string extraButton2Text       = null, string extraButton3Text = null, string checkBoxText = null)
#endif
        {
            txtMessage.Text = message;

            if (!string.IsNullOrEmpty(title))
            {
                Title = title;
            }

            if (colorScheme != null)
            {
                SetValue(ColorSchemeProperty, colorScheme);
            }

            if (owner != null)
            {
                Owner = owner;
            }

            if (!string.IsNullOrEmpty(customOkButtonText))
            {
                OkButtonText = customOkButtonText;
            }
            if (!string.IsNullOrEmpty(customCancelButtonText))
            {
                CancelButtonText = customCancelButtonText;
            }
            if (!string.IsNullOrEmpty(customDiscardButtonText))
            {
                DiscardButtonText = customDiscardButtonText;
            }

            switch (buttonDisplay)
            {
            case MessageDialogButtonDisplay.Auto:
                if (string.IsNullOrEmpty(CancelButtonText))
                {
                    btnCancel.Visibility = Visibility.Collapsed;
                }
                else
                {
                    btnCancel.Visibility = Visibility.Visible;
                    btnCancel.Content    = CancelButtonText;
                }

                if (string.IsNullOrEmpty(DiscardButtonText))
                {
                    btnDiscard.Visibility = Visibility.Collapsed;
                }
                else
                {
                    btnDiscard.Visibility = Visibility.Visible;
                    btnDiscard.Content    = DiscardButtonText;
                }

                if (string.IsNullOrEmpty(OkButtonText))
                {
                    // if Cancel button, Discard button, and Ok button are all null/not shown, reset the Ok button and show that
                    if (btnCancel.Visibility == Visibility.Collapsed && btnDiscard.Visibility == Visibility.Collapsed)
                    {
                        OkButtonText     = "OK";
                        btnOK.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        btnOK.Visibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    btnOK.Content    = OkButtonText;
                    btnOK.Visibility = Visibility.Visible;
                }
                break;

            case MessageDialogButtonDisplay.One:
                btnOK.Content = GetStringOrNull(OkButtonText, "OK");

                btnOK.Visibility      = Visibility.Visible;
                btnCancel.Visibility  = Visibility.Collapsed;
                btnDiscard.Visibility = Visibility.Collapsed;
                break;

            case MessageDialogButtonDisplay.Two:
                btnOK.Content     = GetStringOrNull(OkButtonText, "OK");
                btnCancel.Content = GetStringOrNull(CancelButtonText, "Cancel");

                btnOK.Visibility      = Visibility.Visible;
                btnCancel.Visibility  = Visibility.Visible;
                btnDiscard.Visibility = Visibility.Collapsed;
                break;

            case MessageDialogButtonDisplay.Three:
                btnOK.Content      = GetStringOrNull(OkButtonText, "OK");
                btnCancel.Content  = GetStringOrNull(CancelButtonText, "Cancel");
                btnDiscard.Content = GetStringOrNull(DiscardButtonText, "Discard");

                btnOK.Visibility      = Visibility.Visible;
                btnCancel.Visibility  = Visibility.Visible;
                btnDiscard.Visibility = Visibility.Visible;
                break;

            default:
                // same as "Auto"
                if (string.IsNullOrEmpty(CancelButtonText))
                {
                    btnCancel.Visibility = Visibility.Collapsed;
                }
                else
                {
                    btnCancel.Visibility = Visibility.Visible;
                    btnCancel.Content    = CancelButtonText;
                }

                if (string.IsNullOrEmpty(DiscardButtonText))
                {
                    btnDiscard.Visibility = Visibility.Collapsed;
                }
                else
                {
                    btnDiscard.Visibility = Visibility.Visible;
                    btnDiscard.Content    = DiscardButtonText;
                }

                if (string.IsNullOrEmpty(OkButtonText))
                {
                    // if Cancel button, Discard button, and Ok button are all null/not shown, reset the Ok button and show that
                    if (btnCancel.Visibility == Visibility.Collapsed && btnDiscard.Visibility == Visibility.Collapsed)
                    {
                        OkButtonText     = "OK";
                        btnOK.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        btnOK.Visibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    btnOK.Content    = OkButtonText;
                    btnOK.Visibility = Visibility.Visible;
                }
                break;
            }

            Image = image;

            if (!string.IsNullOrEmpty(extraButton1Text))
            {
                ExtraButton1Text = extraButton1Text;
            }
            if (!string.IsNullOrEmpty(extraButton2Text))
            {
                ExtraButton2Text = extraButton2Text;
            }
            if (!string.IsNullOrEmpty(extraButton3Text))
            {
                ExtraButton3Text = extraButton3Text;
            }
            if (!string.IsNullOrEmpty(checkBoxText))
            {
                CheckBoxText = checkBoxText;
            }

            bool showExtraButtons = false;

            if (!string.IsNullOrEmpty(ExtraButton1Text))
            {
                extraButton1.Content    = ExtraButton1Text;
                extraButton1.Visibility = Visibility.Visible;
                showExtraButtons        = true;
            }

            if (!string.IsNullOrEmpty(ExtraButton2Text))
            {
                extraButton2.Content    = ExtraButton2Text;
                extraButton2.Visibility = Visibility.Visible;
                showExtraButtons        = true;
            }

            if (!string.IsNullOrEmpty(ExtraButton3Text))
            {
                extraButton3.Content    = ExtraButton3Text;
                extraButton3.Visibility = Visibility.Visible;
                showExtraButtons        = true;
            }

            if (!string.IsNullOrEmpty(CheckBoxText))
            {
                chkBox.Content    = CheckBoxText;
                chkBox.Visibility = Visibility.Visible;
            }

            if (showExtraButtons)
            {
                stkExtraButtons.Margin = new Thickness(70, 10, 20, 10);
            }

            switch (defaultButton)
            {
            case MessageDialogResult.OK:
                if (btnOK.Visibility == Visibility.Visible)
                {
                    btnOK.IsDefault = true;
                }
                else
                {
                    btnCancel.IsDefault = true;
                }
                break;

            case MessageDialogResult.Discard:
                btnDiscard.IsDefault = true;
                break;

            case MessageDialogResult.Cancel:
                btnCancel.IsDefault = true;
                break;

            case MessageDialogResult.Extra1:
                if (extraButton1.Visibility == Visibility.Visible)
                {
                    extraButton1.IsDefault = true;
                    btnCancel.IsDefault    = false;
                    btnOK.IsDefault        = false;
                }
                else
                {
                    btnCancel.IsDefault = true;
                }
                break;

            case MessageDialogResult.Extra2:
                if (extraButton2.Visibility == Visibility.Visible)
                {
                    extraButton2.IsDefault = true;
                    btnCancel.IsDefault    = false;
                    btnOK.IsDefault        = false;
                }
                else
                {
                    btnCancel.IsDefault = true;
                }
                break;

            case MessageDialogResult.Extra3:
                if (extraButton3.Visibility == Visibility.Visible)
                {
                    extraButton3.IsDefault = true;
                    btnCancel.IsDefault    = false;
                    btnOK.IsDefault        = false;
                }
                else
                {
                    btnCancel.IsDefault = true;
                }
                break;
            }

            if (Owner != null)
            {
                WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }
            else
            {
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }

            base.ShowDialog();

            return(DialogResult);
        }
Пример #2
0
        /// <summary>
        /// Create a color scheme with high-contrast colors, based upon one of the available options.
        /// </summary>
        /// <param name="hco">The high-contrast scheme option to create.</param>
        /// <returns></returns>
        public static ColorScheme GetHighContrastScheme(HighContrastOption hco)
        {
            ColorScheme cs = new ColorScheme();

            cs.IsHighContrast = true;

            switch (hco)
            {
            case HighContrastOption.WhiteOnBlack:
                cs.MainColor               = Black; //HighContrastPurple;
                cs.SecondaryColor          = Gray;  // items that use main or secondary color should use other options
                cs.BackgroundColor         = Black;
                cs.LightBackgroundColor    = Black;
                cs.SelectionColor          = HighContrastLightBlue;
                cs.HighlightColor          = HighContrastLightBlue;
                cs.SecondHighlightColor    = HighContrastLightBlue;
                cs.ThirdHighlightColor     = HighContrastLightBlue;
                cs.ForegroundColor         = White;
                cs.BorderColor             = White;
                cs.LightDisabledColor      = HighContrastLightGreen;
                cs.DarkDisabledColor       = HighContrastLightGreen;
                cs.WindowTitleBarColor     = HighContrastPurple;
                cs.WindowTitleBarTextColor = White;
                cs.WindowInactiveColor     = HighContrastPurple;
                break;

            case HighContrastOption.GreenOnBlack:
                cs.MainColor               = Black; //HighContrastLightBlue;
                cs.SecondaryColor          = Gray;  // items that use main or secondary color should use other options
                cs.BackgroundColor         = Black;
                cs.LightBackgroundColor    = Black;
                cs.SelectionColor          = HighContrastBlue;
                cs.HighlightColor          = HighContrastBlue;
                cs.SecondHighlightColor    = HighContrastBlue;
                cs.ThirdHighlightColor     = HighContrastBlue;
                cs.ForegroundColor         = HighContrastGreen;
                cs.BorderColor             = White;
                cs.LightDisabledColor      = HighContrastGray;
                cs.DarkDisabledColor       = HighContrastGray;
                cs.WindowTitleBarColor     = HighContrastLightBlue;
                cs.WindowTitleBarTextColor = Black;
                cs.WindowInactiveColor     = HighContrastPurple;
                break;

            case HighContrastOption.BlackOnWhite:
                cs.MainColor               = White; //HighContrastLightBlue;
                cs.SecondaryColor          = Gray;  // items that use main or secondary color should use other options
                cs.BackgroundColor         = White;
                cs.LightBackgroundColor    = White;
                cs.SelectionColor          = HighContrastLightPurple;
                cs.HighlightColor          = HighContrastLightPurple;
                cs.SecondHighlightColor    = HighContrastLightPurple;
                cs.ThirdHighlightColor     = HighContrastLightPurple;
                cs.ForegroundColor         = Black;
                cs.BorderColor             = Black;
                cs.LightDisabledColor      = HighContrastRed;
                cs.DarkDisabledColor       = HighContrastRed;
                cs.WindowTitleBarColor     = HighContrastLightBlue;
                cs.WindowTitleBarTextColor = Black;
                cs.WindowInactiveColor     = HighContrastLightBlue;
                break;

            default:
                break;
            }

            cs.CreateAccentPalette(cs);

            return(cs);
        }
Пример #3
0
        public MessageDialogResult ShowDialog(string message, ColorScheme colorScheme = null, Window owner = null, string title = "Dialog", bool showTwoBottomButtons = true,
                                              MessageDialogImage image  = MessageDialogImage.None, MessageDialogResult defaultButton = MessageDialogResult.Cancel,
                                              string customOkButtonText = null, string customCancelButtonText = null,
                                              string extraButton1Text   = null, string extraButton2Text       = null, string extraButton3Text = null, string checkBoxText = null)
#endif
        {
            txtMessage.Text = message;

            if (!string.IsNullOrEmpty(title))
            {
                Title = title;
            }

            if (colorScheme != null)
            {
                SetValue(ColorSchemeProperty, colorScheme);
            }

            if (owner != null)
            {
                Owner = owner;
            }

            if (!string.IsNullOrEmpty(customOkButtonText))
            {
                OkButtonText = customOkButtonText;
            }
            if (!string.IsNullOrEmpty(customCancelButtonText))
            {
                CancelButtonText = customCancelButtonText;
            }

            btnDiscard.Visibility = Visibility.Collapsed;

            if (showTwoBottomButtons)
            {
                // check if CancelButtonText is still "", as is default
                if (string.IsNullOrEmpty(CancelButtonText))
                {
                    CancelButtonText = "Cancel";
                }

                btnCancel.Content = CancelButtonText;
                btnOK.Content     = OkButtonText;

                btnCancel.Visibility = Visibility.Visible;
                btnOK.Visibility     = Visibility.Visible;
            }
            else if (!string.IsNullOrEmpty(CancelButtonText))
            {
                btnCancel.Content = CancelButtonText;
                btnOK.Content     = OkButtonText;

                btnCancel.Visibility = Visibility.Visible;
                btnOK.Visibility     = Visibility.Visible;
            }
            else
            {
                //_oneButtonDialog = true;

                btnOK.Content = OkButtonText;

                btnCancel.Visibility = Visibility.Collapsed;
                btnOK.Visibility     = Visibility.Visible;
            }

            Image = image;

            if (!string.IsNullOrEmpty(extraButton1Text))
            {
                ExtraButton1Text = extraButton1Text;
            }
            if (!string.IsNullOrEmpty(extraButton2Text))
            {
                ExtraButton2Text = extraButton2Text;
            }
            if (!string.IsNullOrEmpty(extraButton3Text))
            {
                ExtraButton3Text = extraButton3Text;
            }
            if (!string.IsNullOrEmpty(checkBoxText))
            {
                CheckBoxText = checkBoxText;
            }

            bool showExtraButtons = false;

            if (!string.IsNullOrEmpty(ExtraButton1Text))
            {
                extraButton1.Content    = ExtraButton1Text;
                extraButton1.Visibility = Visibility.Visible;
                showExtraButtons        = true;
            }

            if (!string.IsNullOrEmpty(ExtraButton2Text))
            {
                extraButton2.Content    = ExtraButton2Text;
                extraButton2.Visibility = Visibility.Visible;
                showExtraButtons        = true;
            }

            if (!string.IsNullOrEmpty(ExtraButton3Text))
            {
                extraButton3.Content    = ExtraButton3Text;
                extraButton3.Visibility = Visibility.Visible;
                showExtraButtons        = true;
            }

            if (!string.IsNullOrEmpty(CheckBoxText))
            {
                chkBox.Content    = CheckBoxText;
                chkBox.Visibility = Visibility.Visible;
            }

            if (showExtraButtons)
            {
                stkExtraButtons.Margin = new Thickness(70, 10, 20, 10);
            }

            switch (defaultButton)
            {
            case MessageDialogResult.OK:
                if (btnOK.Visibility == Visibility.Visible)
                {
                    btnOK.IsDefault = true;
                }
                else
                {
                    btnCancel.IsDefault = true;
                }
                break;

            case MessageDialogResult.Discard:
                btnDiscard.IsDefault = true;
                break;

            case MessageDialogResult.Cancel:
                btnCancel.IsDefault = true;
                break;

            case MessageDialogResult.Extra1:
                if (extraButton1.Visibility == Visibility.Visible)
                {
                    extraButton1.IsDefault = true;
                    btnCancel.IsDefault    = false;
                    btnOK.IsDefault        = false;
                }
                else
                {
                    btnCancel.IsDefault = true;
                }
                break;

            case MessageDialogResult.Extra2:
                if (extraButton2.Visibility == Visibility.Visible)
                {
                    extraButton2.IsDefault = true;
                    btnCancel.IsDefault    = false;
                    btnOK.IsDefault        = false;
                }
                else
                {
                    btnCancel.IsDefault = true;
                }
                break;

            case MessageDialogResult.Extra3:
                if (extraButton3.Visibility == Visibility.Visible)
                {
                    extraButton3.IsDefault = true;
                    btnCancel.IsDefault    = false;
                    btnOK.IsDefault        = false;
                }
                else
                {
                    btnCancel.IsDefault = true;
                }
                break;
            }

            if (Owner != null)
            {
                WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }
            else
            {
                WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }

            base.ShowDialog();

            return(DialogResult);
        }