Example #1
0
        /// <summary>
        /// Invoked when an unhandled <see cref="E:System.Windows.Input.Keyboard.KeyUp" /> attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.Windows.Input.KeyEventArgs" /> that contains the event data.</param>
        protected override void OnKeyUp(KeyEventArgs e)
        {
            base.OnKeyUp(e);

            if (this.IsHitTestVisible)
            {
                if ((e.Key == Key.Enter) &&
                    (this.DefaultCommandIndex >= 0) &&
                    (this.DefaultCommandIndex < this.Items.Count))
                {
                    MessageDialogButton messageDialogCommand = this.Items
                                                               .OfType <MessageDialogButton>()
                                                               .ElementAtOrDefault(this.DefaultCommandIndex);
                    if ((messageDialogCommand != null) &&
                        messageDialogCommand.Command.CanExecute(messageDialogCommand.CommandParameter))
                    {
                        messageDialogCommand.Command.Execute(messageDialogCommand.CommandParameter);
                    }
                }

                if ((e.Key == Key.Escape) &&
                    (this.CancelCommandIndex >= 0) &&
                    (this.CancelCommandIndex < this.Items.Count))
                {
                    MessageDialogButton messageDialogCommand = this.Items
                                                               .OfType <MessageDialogButton>()
                                                               .ElementAtOrDefault(this.CancelCommandIndex);
                    if ((messageDialogCommand != null) &&
                        messageDialogCommand.Command.CanExecute(messageDialogCommand.CommandParameter))
                    {
                        messageDialogCommand.Command.Execute(messageDialogCommand.CommandParameter);
                    }
                }
            }
        }
Example #2
0
 public void Dismiss(MessageDialogButton button)
 {
     if (AutoHide)
     {
         DialogsManager.HideDialog(this);
     }
     if (m_handler != null)
     {
         m_handler(button);
     }
 }
Example #3
0
        public static MessageBoxResult Show(string text, string title, MessageDialogButton button, [NotNull] string doNotAskAgainKey, Window owner = null)
        {
            var key = $@"__doNotAskAgain:{doNotAskAgainKey}";

            return(Show(text, title, button,
                        new ShowMessageCallbacks(() => ValuesStorage.Get <MessageBoxResult?>(key), k => {
                if (!k.HasValue)
                {
                    ValuesStorage.Remove(key);
                }
                else
                {
                    ValuesStorage.Set(key, k.Value);
                }
            }), owner));
        }
Example #4
0
        /// <summary>
        /// Initializes the MessageDialog window with the message, caption
        /// and the button which have to be displayed.
        /// </summary>
        /// <param name="message">Message to be displayed in the dialog box.</param>
        /// <param name="caption">Caption of the dialog box</param>
        /// <param name="buttons">Buttons which will be displayed to the users.</param>
        public void Initialize(string message, string caption, MessageDialogButton buttons)
        {
            this.txtSequence.Text = message;
            this.txtCaption.Text  = caption;

            if (buttons == MessageDialogButton.YesNo)
            {
                this.btnYes.Visibility = Visibility.Visible;
                this.btnNo.Visibility  = Visibility.Visible;
                this.btnYes.Focus();
            }
            else if (buttons == MessageDialogButton.OK)
            {
                this.btnOk.Visibility = Visibility.Visible;
                this.btnOk.Focus();
            }
        }
Example #5
0
        /// <summary>
        /// Affiche un message
        /// </summary>
        /// <param name="message">le message</param>
        /// <param name="caption">la légende du message</param>
        /// <param name="buttons">les boutons proposés à l'utilisateur</param>
        /// <param name="image">l'image à afficher</param>
        /// <returns>
        /// le résultat du choix de l'utilisateur
        /// </returns>
        public MessageDialogResult Show(string message, string caption,
                                        MessageDialogButton buttons = MessageDialogButton.OK, MessageDialogImage image = MessageDialogImage.None)
        {
            var messageDialog = new MessageDialog()
            {
                Message = message,
                Caption = caption,
                Image   = image,
                Buttons = buttons,
                Owner   = GetCurrentActiveWindow(),
            };

            switch (buttons)
            {
            case MessageDialogButton.OK:
                messageDialog.DefaultButton = MessageDialogResult.OK;
                break;

            case MessageDialogButton.OKCancel:
                messageDialog.DefaultButton = MessageDialogResult.OK;
                break;

            case MessageDialogButton.YesNoCancel:
                messageDialog.DefaultButton = MessageDialogResult.Yes;
                break;

            case MessageDialogButton.YesNo:
                messageDialog.DefaultButton = MessageDialogResult.Yes;
                break;

            default:
                break;
            }

            messageDialog.ShowDialog();
            return(messageDialog.MessageDialogResult);
        }
Example #6
0
        /// <summary>
        /// Show displays our custom MessageDialogBox. The user is allowed
        /// to pass the message, caption and the buttons that has to be displayed
        /// in MessageDialogBox.
        /// </summary>
        /// <param name="message">Message to be displayed in the dialog box.</param>
        /// <param name="caption">Caption of the dialog box</param>
        /// <param name="buttons">Buttons which will be displayed to</param>
        /// <returns>Specifies which MessageDialog button that the user has clicked. </returns>
        public static MessageDialogResult Show(string message, string caption, MessageDialogButton buttons)
        {
            dialog = new MessageDialog();
            dialog.Initialize(message, caption, buttons);

            // initialize the default result
            if (dialog.btnOk.Visibility == Visibility.Visible)
            {
                result = MessageDialogResult.OK;
            }
            else if (dialog.btnNo.Visibility == Visibility.Visible)
            {
                result = MessageDialogResult.No;
            }

            dialog.btnYes.Click += new RoutedEventHandler(OnYesClicked);
            dialog.btnNo.Click  += new RoutedEventHandler(OnNoClicked);
            dialog.btnOk.Click  += new RoutedEventHandler(OnOkClicked);
            dialog.KeyUp        += new System.Windows.Input.KeyEventHandler(OnDialogKeyUp);
            dialog.Closed       += new EventHandler(OnDialogClosed);
            dialog.ShowDialog();

            return(result);
        }
Example #7
0
 public static MessageBoxResult Show(string text, string title, MessageDialogButton button, Window owner = null)
 {
     return(ShowMessageInner(text, title, button, null, owner));
 }
Example #8
0
 public static MessageBoxResult Show(string text, string title, MessageDialogButton button,
                                     ShowMessageCallbacks doNotAskAgainLoadSave, Window owner = null)
 {
     return(ShowMessageInner(text, title, button, doNotAskAgainLoadSave, owner));
 }
Example #9
0
        private static MessageBoxResult ShowMessageInner(string text, string title, MessageDialogButton button,
                                                         ShowMessageCallbacks doNotAskAgainLoadSave, Window owner = null)
        {
            var value = doNotAskAgainLoadSave?.Item1?.Invoke();

            if (value != null)
            {
                return(value.Value);
            }

            FrameworkElement content = new SelectableBbCodeBlock {
                Text   = text,
                Margin = new Thickness(0, 0, 0, 8)
            };

            CheckBox doNotAskAgainCheckbox;

            if (doNotAskAgainLoadSave != null)
            {
                doNotAskAgainCheckbox = new CheckBox {
                    Content = new Label {
                        Content = "Don’t ask again"
                    }
                };

                content = new SpacingStackPanel {
                    Spacing  = 8,
                    Children =
                    {
                        content,
                        doNotAskAgainCheckbox
                    }
                };
            }
            else
            {
                doNotAskAgainCheckbox = null;
            }

            var dlg = new ModernDialog {
                Title   = title,
                Content = new ScrollViewer {
                    Content   = content,
                    MaxWidth  = 640,
                    MaxHeight = 520,
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled
                },
                MinHeight = 0,
                MinWidth  = 0,
                MaxHeight = 640,
                MaxWidth  = 800
            };

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

            dlg.Buttons = button.GetButtons(dlg);
            dlg.ShowDialog();

            if (doNotAskAgainCheckbox != null)
            {
                doNotAskAgainLoadSave.Item2.Invoke(doNotAskAgainCheckbox.IsChecked == true ?
                                                   dlg.MessageBoxResult : (MessageBoxResult?)null);
            }

            return(dlg.MessageBoxResult);
        }