Exemplo n.º 1
0
 protected virtual void OnDefaultButtonClicked(MessageDialogDefaultButton buttonType)
 {
     if (DefaultButtonClicked != null)
     {
         DefaultButtonClicked(this, new DefaultButtonClickedEventArgs(buttonType));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// MessageBox
        /// </summary>
        /// <param name="title">Dialog Title</param>
        /// <param name="message">May contain \n.</param>
        /// <param name="dialogType">Ok, OkCancel, YesNo, YesNoCancel.</param>
        /// <param name="iconType">Info, Warning, Error, Question.</param>
        /// <param name="defaultButton">Cancel_No, Ok_Yes, No_In_Yes_No_Cancel.</param>
        /// <returns>If Type is OkCancel or YesNo returns true when clicking OK or YES otherwise returns false.</returns>
        public static bool MessageBox(string title, string message, MessageDialogType dialogType,
                                      MessageDialogIconType iconType, MessageDialogDefaultButton defaultButton)
        {
            string dialogTypeStr;
            string iconTypeStr;


            switch (dialogType)
            {
            default:
            case MessageDialogType.Ok: dialogTypeStr = "ok"; break;

            case MessageDialogType.OkCancel: dialogTypeStr = "okcancel"; break;

            case MessageDialogType.YesNo: dialogTypeStr = "yesno"; break;

            case MessageDialogType.YesNoCancel: dialogTypeStr = "yesnocancel"; break;
            }

            switch (iconType)
            {
            default:
            case MessageDialogIconType.Info: iconTypeStr = "info"; break;

            case MessageDialogIconType.Warning: iconTypeStr = "warning"; break;

            case MessageDialogIconType.Error: iconTypeStr = "error"; break;

            case MessageDialogIconType.Question: iconTypeStr = "question"; break;
            }

            int result = tinyfd_messageBox(title, message, dialogTypeStr, iconTypeStr, (int)defaultButton);

            return(result == 1);
        }
Exemplo n.º 3
0
        private string GetDefaultButtonContent(MessageDialogDefaultButton buttonType)
        {
            var culture = System.Threading.Thread.CurrentThread.CurrentUICulture;
            var lang    = culture.TwoLetterISOLanguageName;

            switch (buttonType)
            {
            case MessageDialogDefaultButton.Ok: if (lang == "de")
                {
                    return("OK");
                }
                else if (lang == "en")
                {
                    return("OK");
                }
                break;

            case MessageDialogDefaultButton.Cancel: if (lang == "de")
                {
                    return("Abbrechen");
                }
                else if (lang == "en")
                {
                    return("Cancel");
                }
                break;

            case MessageDialogDefaultButton.Yes: if (lang == "de")
                {
                    return("Ja");
                }
                else if (lang == "en")
                {
                    return("Yes");
                }
                break;

            case MessageDialogDefaultButton.No: if (lang == "de")
                {
                    return("Nein");
                }
                else if (lang == "en")
                {
                    return("No");
                }
                break;

            case MessageDialogDefaultButton.Close: if (lang == "de")
                {
                    return("Schließen");
                }
                else if (lang == "en")
                {
                    return("Close");
                }
                break;
            }
            return(string.Empty);
        }
Exemplo n.º 4
0
        private void RefreshButtonCommand(MessageDialogDefaultButton buttonType, ICommand command)
        {
            var button = (from b in this.Commands
                          where b.Tag is MessageDialogDefaultButton &&
                          ((MessageDialogDefaultButton)b.Tag).Equals(buttonType)
                          select b).FirstOrDefault();

            if (button != null)
            {
                button.Command = command;
            }
        }
Exemplo n.º 5
0
        private void OnDefaultButtonClicked(object sender, RoutedEventArgs e)
        {
            this.IsOpen = false;
            var button = sender as Button;
            var tag    = button.Tag;

            if (tag != null && tag is MessageDialogDefaultButton)
            {
                var buttonType = (MessageDialogDefaultButton)tag;
                this.DialogResult = buttonType;
                this.OnDefaultButtonClicked(buttonType);
            }
        }
Exemplo n.º 6
0
        private Button CreateButton(MessageDialogDefaultButton buttonType, ICommand command)
        {
            var button = new Button
            {
                Content   = this.GetDefaultButtonContent(buttonType),
                Command   = command,
                Style     = this.DefaultButtonStyle,
                Tag       = buttonType,
                IsDefault = (buttonType == MessageDialogDefaultButton.Ok || buttonType == MessageDialogDefaultButton.Yes),
                IsCancel  = (buttonType == MessageDialogDefaultButton.Cancel || buttonType == MessageDialogDefaultButton.Close || buttonType == MessageDialogDefaultButton.No),
            };

            button.AddHandler(Button.ClickEvent, new RoutedEventHandler(this.OnDefaultButtonClicked));
            return(button);
        }
Exemplo n.º 7
0
 public DefaultButtonClickedEventArgs(MessageDialogDefaultButton buttonType)
 {
     this.ButtonType = buttonType;
 }