Exemple #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);
        }
Exemple #2
0
        /// <summary>
        /// Display this message dialog.
        /// </summary>
        /// <param name="message">The message to display.</param>
        /// <param name="colorScheme">The color scheme to use with the dialog. Use <c>null</c> if already set via property.</param>
        /// <param name="owner">The owner window of this dialog. Use <c>null</c> if already set via property.</param>
        /// <param name="title">The window title for this dialog. Use <c>null</c> if already set via property.</param>
        /// <param name="buttonDisplay">Determine how many buttons should be displayed at the bottom of the dialog, either [OK], [OK] and [Cancel], or [OK] [Discard] and [Cancel].</param>
        /// <param name="image">The image to display with this dialog.</param>
        /// <param name="defaultButton">The button to have selected by default when the dialog opens. (DOESN'T CURRENTLY WORK)</param>
        /// <param name="customOkButtonText">The text to use in the OK button. Use <c>null</c> if already set via property.</param>
        /// <param name="customCancelButtonText">The text to use in the Cancel button. Use <c>null</c> if already set via property.</param>
        /// <param name="customDiscardButtonText">The text to use in the Discard button. Use <c>null</c> if already set via property.</param>
        /// <param name="extraButton1Text">The text to use in the first extra button. If this is set to a null or empty string, this button will not be displayed.</param>
        /// <param name="extraButton2Text">The text to use in the second extra button. If this is set to a null or empty string, this button will not be displayed.</param>
        /// <param name="extraButton3Text">The text to use in the third extra button. If this is set to a null or empty string, this button will not be displayed.</param>
        /// <param name="checkBoxText">The text to use in the check box. If this is set to a null or empty string, the check box will not be displayed.</param>
#if NETCOREAPP
        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)