Beispiel #1
0
        public Task <MessageResult> ShowAsync(string message, string caption = "", string helpLink                 = null,
                                              MessageButton button           = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
            var tcs = new TaskCompletionSource <MessageResult>();

#pragma warning disable AvoidAsyncVoid
            _dispatcherService.BeginInvoke(async() =>
#pragma warning restore AvoidAsyncVoid
            {
                var previousCursor   = Mouse.OverrideCursor;
                Mouse.OverrideCursor = null;

                var vm = _viewModelFactory.CreateViewModel <HelpLinkMessageBoxViewModel>(null, null);

                vm.Message  = message;
                vm.Button   = button;
                vm.Icon     = icon;
                vm.HelpLink = helpLink;

                vm.SetTitle(caption);

                await _uiVisualizerService.ShowDialogAsync(vm);

                Mouse.OverrideCursor = previousCursor;

                tcs.TrySetResult(vm.Result);
            });

            return(tcs.Task);
        }
 /// <summary>Shows a message with an error icon.</summary>
 ///
 /// <param name="owner">The owner window for this dialog message.</param>
 /// <param name="message">The text message.</param>
 /// <param name="title">The message window title.</param>
 /// <param name="button">The message buttons to display.</param>
 public MessageResult ShowError(IWindow owner, string message, string title, MessageButton button = MessageButton.OK)
 {
     return(ui.Invoke(() => {
         SystemSounds.Hand.Play();
         return (MessageResult)MessageBox.Show((Window)owner.Window, message, title, (MessageBoxButton)button, MessageBoxImage.Error);
     }));
 }
 private MessageResult ShowMessage(string messageBoxText, string caption, MessageButton button, MessageImage icon,
     MessageResult defaultResult)
 {
     DialogResult result = MessageBox.Show(messageBoxText, caption, ConvertButtons(button), ConvertImage(icon),
         ConvertDefaultResult(button, defaultResult));
     return ConvertResult(result);
 }
 MessageResult IMessageBoxService.Show(string messageBoxText, string caption, MessageButton button,
                                       MessageIcon icon, MessageResult defaultResult)
 {
     return
         (XtraMessageBox.Show(messageBoxText, caption, button.ToMessageBoxButtons(), icon.ToMessageBoxIcon(),
                              defaultResult.ToMessageBoxDefaultButton(button)).ToMessageResult());
 }
        public static string GetAsText(this IMessageService messageService, string message, MessageButton messageButton)
        {
            var buttons = string.Empty;

            switch (messageButton)
            {
                case MessageButton.OK:
                    buttons = "[ OK ]";
                    break;

                case MessageButton.OKCancel:
                    buttons = "[ OK ] | [ Cancel ]";
                    break;

                case MessageButton.YesNo:
                    buttons = "[ Yes ] | [ No ]";
                    break;

                case MessageButton.YesNoCancel:
                    buttons = "[ Yes ] | [ No ] | [ Cancel ]";
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }

            return messageService.GetAsText(message, buttons);
        }
        /// <summary>
        /// Shows the message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>The message result.</returns>
        /// <exception cref="ArgumentException">The <paramref name="message"/> is <c>null</c> or whitespace.</exception>
        protected virtual async Task<MessageResult> ShowMessageBox(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
            // TODO: Add translations for system

            var result = MessageBoxResult.None;
            var messageBoxButton = TranslateMessageButton(button);
            var messageDialog = new MessageDialog(message, caption);

            if (Enum<MessageButton>.Flags.IsFlagSet(button, MessageButton.OK) || 
                Enum<MessageButton>.Flags.IsFlagSet(button, MessageButton.OKCancel))
            {
                messageDialog.Commands.Add(new UICommand("OK", cmd => result = MessageBoxResult.OK));
            }

            if (Enum<MessageButton>.Flags.IsFlagSet(button, MessageButton.YesNo) ||
                Enum<MessageButton>.Flags.IsFlagSet(button, MessageButton.YesNoCancel))
            {
                messageDialog.Commands.Add(new UICommand("Yes", cmd => result = MessageBoxResult.Yes));
                messageDialog.Commands.Add(new UICommand("No", cmd => result = MessageBoxResult.No));
            }

            if (Enum<MessageButton>.Flags.IsFlagSet(button, MessageButton.OKCancel) ||
                Enum<MessageButton>.Flags.IsFlagSet(button, MessageButton.YesNoCancel))
            {
                messageDialog.Commands.Add(new UICommand("Cancel", cmd => result = MessageBoxResult.Cancel));
                messageDialog.CancelCommandIndex = (uint)messageDialog.Commands.Count - 1;
            }

            await messageDialog.ShowAsync();

            return TranslateMessageBoxResult(result);
        }
Beispiel #7
0
		public TextMessage(string text, string title, MessageButton button)
		{
			Text = text;
			Title = title;
			Button = button;
			Result = MessageResult.OK;
		}
        /// <summary>
        /// The message button to default result message.
        /// </summary>
        /// <param name="button">The button.</param>
        /// <returns>The <see cref="ResultMessage" />.</returns>
        public static ResultMessage MessageButtonToDefaultResultMessage(MessageButton button)
        {
            switch (button)
            {
            case MessageButton.ButtonsOk:
                return(ResultMessage.ButtonOk);

            case MessageButton.ButtonsOkCancel:
                return(ResultMessage.ButtonOk);

            case MessageButton.ButtonsRetryCancel:
                return(ResultMessage.ButtonCancel);

            case MessageButton.ButtonsAbortRetryIgnore:
                return(ResultMessage.ButtonIgnore);

            case MessageButton.ButtonsYesNo:
                return(ResultMessage.ButtonYes);

            case MessageButton.ButtonsYesNoCancel:
                return(ResultMessage.ButtonYes);

            default:
                throw new ArgumentOutOfRangeException("button");
            }
        }
 MessageResult IMessageBoxService.Show(string messageBoxText, string caption, MessageButton button, MessageIcon icon, MessageResult defaultResult) {
     var owner = AssociatedObject.With(x => Window.GetWindow(x));
     if(owner == null)
         return MessageBox.Show(messageBoxText, caption, button.ToMessageBoxButton(), icon.ToMessageBoxImage(), defaultResult.ToMessageBoxResult()).ToMessageResult();
     else
         return MessageBox.Show(owner, messageBoxText, caption, button.ToMessageBoxButton(), icon.ToMessageBoxImage(), defaultResult.ToMessageBoxResult()).ToMessageResult();
 }
        /// <summary>
        /// Converts <see cref="MessageButton" /> to <see cref="MessageBoxButton" />.
        /// </summary>
        /// <param name="button">The button enumeration.</param>
        /// <returns>The message button enumeration.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// button
        /// or
        /// button
        /// or
        /// button
        /// </exception>
        public static MessageBoxButton MessageButtonToMessageBoxButton(MessageButton button)
        {
            MessageBoxButton messageBoxButton;

            switch (button)
            {
            case MessageButton.ButtonsOk:
                messageBoxButton = MessageBoxButton.OK;
                break;

            case MessageButton.ButtonsOkCancel:
                messageBoxButton = MessageBoxButton.OKCancel;
                break;

            case MessageButton.ButtonsRetryCancel:
                throw new ArgumentOutOfRangeException("button");

            case MessageButton.ButtonsAbortRetryIgnore:
                throw new ArgumentOutOfRangeException("button");

            case MessageButton.ButtonsYesNo:
                messageBoxButton = MessageBoxButton.YesNo;
                break;

            case MessageButton.ButtonsYesNoCancel:
                messageBoxButton = MessageBoxButton.YesNoCancel;
                break;

            default:
                throw new ArgumentOutOfRangeException("button");
            }

            return(messageBoxButton);
        }
        /// <summary>
        /// Shows the specified message and returns the result.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>The <see cref="MessageResult"/>.</returns>
        public MessageResult Show(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None) {
#if WinRT
            return ShowMessageBox(message, caption, button, icon).Result;
#else
            return ShowMessageBox(message, caption, button, icon);
#endif
        }
        private void UpdateMessageButton(MessageButton button)
        {
            switch (button)
            {
            case MessageButton.OK:
                OKVisibility = Visibility.Visible;
                break;

            case MessageButton.OKCancel:
                OKVisibility     = Visibility.Visible;
                CancelVisibility = Visibility.Visible;
                break;

            case MessageButton.YesNo:
                YesVisibility = Visibility.Visible;
                NoVisibility  = Visibility.Visible;
                break;

            case MessageButton.YesNoCancel:
                YesVisibility    = Visibility.Visible;
                NoVisibility     = Visibility.Visible;
                CancelVisibility = Visibility.Visible;
                break;
            }
        }
Beispiel #13
0
        public MainPage()
        {
            InitializeComponent();

            MessageLabel.SetBinding(Button.TextProperty, "ChangeText", BindingMode.OneWayToSource);
            MessageButton.SetBinding(Button.CommandProperty, "ButtonCommand");
        }
Beispiel #14
0
 public CustomMessageBox()
 {
     InitializeComponent();
     dialogResult  = System.Windows.Forms.DialogResult.OK;
     msgButtonType = MessageButton.OK;
     isButton      = false;
 }
Beispiel #15
0
 public TextMessage(string text, string title, MessageButton button)
 {
     Text   = text;
     Title  = title;
     Button = button;
     Result = MessageResult.OK;
 }
 public SessionMessage(MessageType messageType, MessageBehaviors behavior, string message, string key,string caption, MessageButton? messageButtons, MessageIcon? messageIcon)
 {
     if (behavior == MessageBehaviors.Modal && (!messageButtons.HasValue || !messageIcon.HasValue))
     {
         messageButtons = messageButtons ?? MessageButton.Ok;
         if(!messageIcon.HasValue)
         {
             switch(messageType)
             {
                 case MessageType.Error:
                     messageIcon = MessageIcon.Error;
                     break;
                 case MessageType.Info:
                     messageIcon = MessageIcon.Information;
                     break;
                 case MessageType.Success:
                     messageIcon = MessageIcon.Success;
                     break;
                 case MessageType.Warning:
                     messageIcon = MessageIcon.Warning;
                     break;
                 default:
                     messageIcon = MessageIcon.Information;
                     break;
             }
         }
     }
     Key = key;
     Message = message;
     Caption = caption;
     Type = messageType;
     Behavior = behavior;
     Buttons = messageButtons;
     Icon = messageIcon;
 }
Beispiel #17
0
        public Task <MessageResult> ShowAsync(string messageBoxText, string caption = "",
                                              MessageButton button        = MessageButton.Ok, MessageImage icon      = MessageImage.None,
                                              MessageResult defaultResult = MessageResult.None, IDataContext context = null)
        {
            bool             success;
            MessageBoxButton buttons = ConvertMessageBoxButtons(button, out success);

            Should.BeSupported(success, "The MessageBoxAdapter doesn't support {0} value", button);

            if (_threadManager.IsUiThread)
            {
                MessageBoxResult result = MessageBox.Show(messageBoxText, caption, buttons,
                                                          ConvertMessageBoxImages(icon),
                                                          ConvertMessageBoxResults(defaultResult));
                return(ToolkitExtensions.FromResult(ConvertMessageBoxResult(result)));
            }
            var tcs = new TaskCompletionSource <MessageResult>();

            _threadManager.InvokeOnUiThreadAsync(() =>
            {
                MessageBoxResult result = MessageBox.Show(messageBoxText, caption, buttons,
                                                          ConvertMessageBoxImages(icon), ConvertMessageBoxResults(defaultResult));
                tcs.SetResult(ConvertMessageBoxResult(result));
            });
            return(tcs.Task);
        }
Beispiel #18
0
        public override Task<MessageResult> ShowAsync(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
            Argument.IsNotNullOrWhitespace("message", message);

            Log.Info("Showing message to the user:\n\n{0}", this.GetAsText(message, button));

            var tcs = new TaskCompletionSource<MessageResult>();

            _dispatcherService.BeginInvoke(async () =>
            {
                var previousCursor = Mouse.OverrideCursor;
                Mouse.OverrideCursor = null;

                var vm = _viewModelFactory.CreateViewModel<MessageBoxViewModel>(null, null);

                vm.Message = message;
                vm.Button = button;
                vm.Icon = icon;

                vm.SetTitle(caption);

                await _uiVisualizerService.ShowDialogAsync(vm);

                Mouse.OverrideCursor = previousCursor;

                Log.Info("Result of message: {0}", vm.Result);

                tcs.TrySetResult(vm.Result);
            });

            return tcs.Task;
        }
        /// <summary>
        /// Shows the message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>The message result.</returns>
        /// <exception cref="ArgumentException">The <paramref name="message"/> is <c>null</c> or whitespace.</exception>
        protected virtual Task<MessageResult> ShowMessageBoxAsync(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
            Argument.IsNotNullOrWhitespace("message", message);

            var tcs = new TaskCompletionSource<MessageResult>();

            _dispatcherService.BeginInvoke(() =>
            {
                MessageBoxResult result;
                var messageBoxButton = TranslateMessageButton(button);
                var messageBoxImage = TranslateMessageImage(icon);

                var activeWindow = Application.Current.GetActiveWindow();
                if (activeWindow != null)
                {
                    result = MessageBox.Show(activeWindow, message, caption, messageBoxButton, messageBoxImage);
                }
                else
                {
                    result = MessageBox.Show(message, caption, messageBoxButton, messageBoxImage);
                }

                tcs.SetResult(TranslateMessageBoxResult(result));
            });

            return tcs.Task;
        }
        private static MessageResult ConvertMessageBoxResult(MessageBoxResult messageBox,
                                                             MessageButton buttons)
        {
            switch (messageBox)
            {
            case MessageBoxResult.OK:
                if (buttons == MessageButton.YesNo ||
                    buttons == MessageButton.YesNoCancel)
                {
                    return(MessageResult.Yes);
                }
                return(MessageResult.Ok);

            case MessageBoxResult.Cancel:
                if (buttons == MessageButton.YesNo ||
                    buttons == MessageButton.YesNoCancel)
                {
                    return(MessageResult.No);
                }
                return(MessageResult.Cancel);

            case MessageBoxResult.Yes:
                return(MessageResult.Yes);

            case MessageBoxResult.No:
                return(MessageResult.No);

            default:
                return(MessageResult.None);
            }
        }
Beispiel #21
0
        private static MessageBoxButtons ConvertButtons(MessageButton buttons)
        {
            switch (buttons)
            {
            case MessageButton.Ok:
                return(MessageBoxButtons.OK);

            case MessageButton.OkCancel:
                return(MessageBoxButtons.OKCancel);

            case MessageButton.YesNo:
                return(MessageBoxButtons.YesNo);

            case MessageButton.YesNoCancel:
                return(MessageBoxButtons.YesNoCancel);

            case MessageButton.AbortRetryIgnore:
                return(MessageBoxButtons.AbortRetryIgnore);

            case MessageButton.RetryCancel:
                return(MessageBoxButtons.RetryCancel);

            default:
                return(MessageBoxButtons.OK);
            }
        }
        public static Task <MessageResult> ShowDialog(this IDialogService service, MessageButton dialogButtons, string title, string documentType, object viewModel)
        {
#endif
            VerifyService(service);
            var res = service.ShowDialog(UICommand.GenerateFromMessageButton(dialogButtons, GetLocalizer(service)), title, documentType, viewModel, null, null);
            return(GetMessageResult(res));
        }
Beispiel #23
0
        public FormMessage InitData(string errorMsg, string title, MessageIcon icon, MessageButton btn)
        {
            lblMsg.Text = errorMsg;//为错误消息赋值
            this.Text   = title;
            switch (icon)
            {
            case MessageIcon.Error:
                pictureEditIcon.Image = UResource.msg_icon_error;
                break;

            case MessageIcon.Info:
                pictureEditIcon.Image = UResource.msg_icon_info;
                break;

            case MessageIcon.Check:
                pictureEditIcon.Image = UResource.msg_icon_check;
                break;

            case MessageIcon.Question:
                pictureEditIcon.Image = UResource.msg_icon_question;
                break;

            case MessageIcon.Warning:
                pictureEditIcon.Image = UResource.msg_icon_warning;
                break;

            case MessageIcon.Warning2:
                pictureEditIcon.Image = UResource.msg_icon_warning2;
                break;
            }
            SetControlLocationSize(icon, btn);
            return(this);
        }
        private void ShowMessage(string messageBoxText, string caption, MessageButton button,
                                 MessageResult defaultResult,
                                 TaskCompletionSource <MessageResult> tcs)
        {
            var messageDialog = new MessageDialog(messageBoxText, caption);

            switch (button)
            {
            case MessageButton.Ok:
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.Ok, tcs));
                break;

            case MessageButton.OkCancel:
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.Ok, tcs));
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.Cancel, tcs));
                break;

            case MessageButton.YesNo:
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.Yes, tcs));
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.No, tcs));
                break;

            case MessageButton.YesNoCancel:
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.Yes, tcs));
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.No, tcs));
                if (ApplicationSettings.Platform.Platform != PlatformType.WinPhone)
                {
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Cancel, tcs));
                }
                break;

            case MessageButton.AbortRetryIgnore:
                if (ApplicationSettings.Platform.Platform == PlatformType.WinPhone)
                {
                    throw ExceptionManager.EnumOutOfRange("button", button);
                }
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.Abort, tcs));
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.Retry, tcs));
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.Ignore, tcs));
                break;

            case MessageButton.RetryCancel:
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.Retry, tcs));
                messageDialog.Commands.Add(CreateUiCommand(MessageResult.Cancel, tcs));
                break;

            default:
                tcs.SetResult(MessageResult.None);
                return;
            }
            for (int i = 0; i < messageDialog.Commands.Count; i++)
            {
                if (defaultResult == (MessageResult)messageDialog.Commands[i].Id)
                {
                    messageDialog.DefaultCommandIndex = (uint)i;
                    break;
                }
            }
            messageDialog.ShowAsync();
        }
        static MessageResult ShowMessageBox(string message, string caption, MessageButton button, MessageImage icon)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentNullException("message");
            }

            var result           = MessageBoxResult.None;
            var messageBoxButton = TranslateMessageButton(button);

#if NET
            var messageBoxImage = TranslateMessageImage(icon);

            var activeWindow = GetActiveWindow();
            if (activeWindow != null)
            {
                result = MessageBox.Show(activeWindow, message, caption, messageBoxButton, messageBoxImage);
            }
            else
            {
                result = MessageBox.Show(message, caption, messageBoxButton, messageBoxImage);
            }
#else
            result = MessageBox.Show(message, caption, messageBoxButton);
#endif

            return(TranslateMessageBoxResult(result));
        }
        public static MessageResult ShowDialog(this IDialogService service, MessageButton dialogButtons, string title, string documentType, object parameter, object parentViewModel)
        {
            VerifyService(service);
            var res = service.ShowDialog(UICommand.GenerateFromMessageButton(dialogButtons, GetLocalizer(service)), title, documentType, null, parameter, parentViewModel);

            return(GetMessageResult(res));
        }
        protected override async Task<MessageResult> ShowMessageBoxAsync(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
            var window = Application.Current.MainWindow as MetroWindow;
            if (window == null)
            {
                return MessageResult.Cancel;
            }

            var style = MessageDialogStyle.Affirmative;
            var affirmativeResult = MessageResult.OK;
            var negativeResult = MessageResult.No;
            var auxiliaryResult = MessageResult.Cancel;

            switch (button)
            {
                case MessageButton.OK:
                    style = MessageDialogStyle.Affirmative;
                    affirmativeResult = MessageResult.OK;
                    break;

                case MessageButton.OKCancel:
                    style = MessageDialogStyle.AffirmativeAndNegative;
                    affirmativeResult = MessageResult.OK;
                    negativeResult = MessageResult.Cancel;
                    break;

                case MessageButton.YesNo:
                    style = MessageDialogStyle.AffirmativeAndNegative;
                    affirmativeResult = MessageResult.Yes;
                    negativeResult = MessageResult.No;
                    break;

                case MessageButton.YesNoCancel:
                    style = MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary;
                    affirmativeResult = MessageResult.Yes;
                    negativeResult = MessageResult.No;
                    auxiliaryResult = MessageResult.Cancel;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("button");
            }

            var result = await window.ShowMessageAsync(caption, message, style);
            switch (result)
            {
                case MessageDialogResult.Negative:
                    return negativeResult;

                case MessageDialogResult.Affirmative:
                    return affirmativeResult;

                case MessageDialogResult.FirstAuxiliary:
                    return auxiliaryResult;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #28
0
 public static MessageBoxButtons ToMessageBoxButtons(this MessageButton button) {
     switch(button) {
         case MessageButton.OKCancel: return MessageBoxButtons.OKCancel;
         case MessageButton.YesNo: return MessageBoxButtons.YesNo;
         case MessageButton.YesNoCancel: return MessageBoxButtons.YesNoCancel;
         default: return MessageBoxButtons.OK;
     }
 }
Beispiel #29
0
        public MessageResult ShowMessageBox(string message, string caption, MessageButton messageButton, MessageImage MessageImage, MessageResult messageResult)
        {
            MessageBoxButton button = (MessageBoxButton)messageButton;
            MessageBoxImage  image  = (MessageBoxImage)MessageImage;
            MessageBoxResult result = (MessageBoxResult)messageResult;

            return((MessageResult)MessageBox.Show(message, caption, button, image, result, MessageBoxOptions.ServiceNotification));
        }
Beispiel #30
0
        private MessageResult ShowMessage(string messageBoxText, string caption, MessageButton button, MessageImage icon,
                                          MessageResult defaultResult)
        {
            DialogResult result = MessageBox.Show(messageBoxText, caption, ConvertButtons(button), ConvertImage(icon),
                                                  ConvertDefaultResult(button, defaultResult));

            return(ConvertResult(result));
        }
        /// <summary>
        /// Shows the specified message and returns the result.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>The <see cref="MessageResult"/>.</returns>
        public MessageResult Show(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
#if WinRT
            return(ShowMessageBox(message, caption, button, icon).Result);
#else
            return(ShowMessageBox(message, caption, button, icon));
#endif
        }
        public static MessageResult ShowMessage(this IMessageBoxService service, string messageBoxText, string caption, MessageButton button) {
#if !SILVERLIGHT
            return service.ShowMessage(messageBoxText, caption, button, MessageIcon.None);
#else
            VerifyService(service);
            return service.Show(messageBoxText, caption, button, MessageResult.None);
#endif
        }
 public MessageResult Show(string messageBoxText, string caption, MessageButton button, MessageResult defaultResult) {
     MessageBoxTest = messageBoxText;
     Caption = caption;
     Button = button;
     DefaultResult = defaultResult;
     ShowCount++;
     return Result;
 }
Beispiel #34
0
    // ------------------------------------------------------------------------
    private void DrawChatOptions(Message message)
    {
        if (message == null)
        {
            Debug.LogError("Message null.");
            return;
        }
        if (!message.Player)
        {
            Debug.LogError("Hecked up script config. NPC has chat options.");
            return;
        }
        if (!message.HasOptions())
        {
            Debug.LogError("Attempting to draw options for message with no options.");
            return;
        }

        // if we've answered this question multiple times, mark this convo done
        if (m_activeChat.VisitedMessages.FindAll(m => m.Node == message.Node).Count > 1)
        {
            FinishConvo();
            return;
        }

        for (int i = 0; i < message.Options.Length; i++)
        {
            // if we've already been to this conversation option,
            // skip drawing whatever option we selected last time
            if (message.MadeSelection() && i == message.OptionSelection)
            {
                continue;
            }

            // draw bubble
            GameObject option = Instantiate(
                MessageOptionPrefab,
                ChatOptionsParent
                ) as GameObject;

            // setup bubble
            MessageButton messageButton = option.GetComponent <MessageButton>();

            // check if clue needs met
            if (PhoneOS.ClueRequirementMet(message.ClueNeeded[i]))
            {
                // set button text & hook up option function
                messageButton.Text.text = message.Options[i];
                SetButtonListener(messageButton.Button, message, i);
                //Debug.Log("created option [" + message.options[i] + "] with index " + i + " for message " + message.node);
            }
            else
            {
                // mark it as unavilable
                messageButton.Text.text = "[clue needed]";
            }
        }
    }
        static List <UICommand> GenerateFromMessageButton(MessageButton dialogButtons, bool usePlatformSpecificTag, IMessageButtonLocalizer buttonLocalizer, MessageResult?defaultButton, MessageResult?cancelButton)
        {
            List <UICommand> commands = new List <UICommand>();

            if (dialogButtons == MessageButton.OK)
            {
                UICommand okCommand = CreateDefaultButtonCommand(MessageResult.OK, usePlatformSpecificTag, buttonLocalizer.Localize);
                okCommand.IsDefault = defaultButton == null || defaultButton == MessageResult.OK;
                okCommand.IsCancel  = cancelButton == MessageResult.OK;

                commands.Add(okCommand);
                return(commands);
            }
            if (dialogButtons == MessageButton.OKCancel)
            {
                UICommand okCommand     = CreateDefaultButtonCommand(MessageResult.OK, usePlatformSpecificTag, buttonLocalizer.Localize);
                UICommand cancelCommand = CreateDefaultButtonCommand(MessageResult.Cancel, usePlatformSpecificTag, buttonLocalizer.Localize);
                okCommand.IsDefault     = defaultButton == null || defaultButton == MessageResult.OK;
                cancelCommand.IsDefault = defaultButton == MessageResult.Cancel;
                okCommand.IsCancel      = cancelButton == MessageResult.OK;
                cancelCommand.IsCancel  = cancelButton == null || cancelButton == MessageResult.Cancel;

                commands.Add(okCommand);
                commands.Add(cancelCommand);
                return(commands);
            }
            if (dialogButtons == MessageButton.YesNo)
            {
                UICommand yesCommand = CreateDefaultButtonCommand(MessageResult.Yes, usePlatformSpecificTag, buttonLocalizer.Localize);
                UICommand noCommand  = CreateDefaultButtonCommand(MessageResult.No, usePlatformSpecificTag, buttonLocalizer.Localize);
                yesCommand.IsDefault = defaultButton == null || defaultButton == MessageResult.Yes;
                noCommand.IsDefault  = defaultButton == MessageResult.No;
                yesCommand.IsCancel  = cancelButton == MessageResult.Yes;
                noCommand.IsCancel   = cancelButton == null || cancelButton == MessageResult.No;

                commands.Add(yesCommand);
                commands.Add(noCommand);
                return(commands);
            }
            if (dialogButtons == MessageButton.YesNoCancel)
            {
                UICommand yesCommand    = CreateDefaultButtonCommand(MessageResult.Yes, usePlatformSpecificTag, buttonLocalizer.Localize);
                UICommand noCommand     = CreateDefaultButtonCommand(MessageResult.No, usePlatformSpecificTag, buttonLocalizer.Localize);
                UICommand cancelCommand = CreateDefaultButtonCommand(MessageResult.Cancel, usePlatformSpecificTag, buttonLocalizer.Localize);
                yesCommand.IsDefault    = defaultButton == null || defaultButton == MessageResult.Yes;
                noCommand.IsDefault     = defaultButton == MessageResult.No;
                cancelCommand.IsDefault = defaultButton == MessageResult.Cancel;
                yesCommand.IsCancel     = cancelButton == MessageResult.Yes;
                noCommand.IsCancel      = cancelButton == null || cancelButton == MessageResult.No;
                cancelCommand.IsCancel  = cancelButton == null || cancelButton == MessageResult.Cancel;

                commands.Add(yesCommand);
                commands.Add(noCommand);
                commands.Add(cancelCommand);
                return(commands);
            }
            return(commands);
        }
Beispiel #36
0
        /// <summary>
        /// Shows an information message to the user and allows a callback operation when the message is completed.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <param name="completedCallback">The callback to invoke when the message is completed. Can be <c>null</c>.</param>
        /// <remarks>
        /// There is no garantuee that the method will be executed asynchronous, only that the <paramref name="completedCallback"/>
        /// will be invoked when the message is dismissed.
        /// </remarks>
        /// <exception cref="ArgumentException">The <paramref name="message"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentException">The <paramref name="caption"/> is <c>null</c> or whitespace.</exception>
        public void ShowAsync(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None, Action <MessageResult> completedCallback = null)
        {
            var result = Show(message, caption, button, icon);

            if (completedCallback != null)
            {
                completedCallback(result);
            }
        }
 static MessageBoxButton TranslateMessageButton(MessageButton button) {
     try {
         var value = button.ToString();
         return (MessageBoxButton) Enum.Parse(typeof (MessageBoxButton), value, true);
     }
     catch (Exception) {
         throw new NotSupportedException(string.Format("Unfortunately, the default MessageBox class of does not support '{0}' button.", button));
     }
 }
 public Task<MessageResult> ShowDialogAsync(string content, string title, MessageButton button)
 {
     return Task.Run<MessageResult>(() =>
     {
         MessageBoxButton mbButton = (button == MessageButton.OKCancel ? MessageBoxButton.OKCancel : MessageBoxButton.OK);
         var result = MessageBox.Show(content, title, mbButton);
         return (result == MessageBoxResult.OK ? MessageResult.OK : MessageResult.Cancel);
     });
 }
Beispiel #39
0
        /// <summary>
        /// 显示消息窗口
        /// </summary>
        /// <param name="message">要显示的消息</param>
        /// <param name="caption">消息框的标题</param>
        /// <param name="messageButtonType">消息框的类型</param>
        /// <returns>是否点击了“是”或者“确定”按钮</returns>
        public static bool?Show(string message, string caption, MessageButton messageButtonType)
        {
            MessageWindow messageWindow = new MessageWindow();

            messageWindow.Caption           = caption;
            messageWindow.Message           = message;
            messageWindow.MessageButtonType = messageButtonType;
            return(messageWindow.ShowDialog());
        }
Beispiel #40
0
        /// <summary>
        /// Shows the specified message and returns the result.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>The <see cref="MessageResult"/>.</returns>
        /// <exception cref="ArgumentException">The <paramref name="message"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="ArgumentException">The <paramref name="caption"/> is <c>null</c> or whitespace.</exception>
        public async Task <MessageResult> Show(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
            if (ExpectedResults.Count == 0)
            {
                throw new Exception(ResourceHelper.GetString("NoExpectedResultsInQueueForUnitTest"));
            }

            return(ExpectedResults.Dequeue());
        }
 public Task <MessageResult> ShowDialogAsync(string content, string title, MessageButton button)
 {
     return(Task.Run <MessageResult>(() =>
     {
         MessageBoxButton mbButton = (button == MessageButton.OKCancel ? MessageBoxButton.OKCancel : MessageBoxButton.OK);
         var result = MessageBox.Show(content, title, mbButton);
         return (result == MessageBoxResult.OK ? MessageResult.OK : MessageResult.Cancel);
     }));
 }
 MessageResult IMessageBoxService.Show(string messageBoxText, string caption, MessageButton button, MessageIcon icon, MessageResult defaultResult)
 {
     MessageBoxText = messageBoxText;
     Caption        = caption;
     Button         = button;
     Icon           = icon;
     DefaultResult  = defaultResult;
     return(Result);
 }
Beispiel #43
0
        public MainPage()
        {
            InitializeComponent();

            MessageLabel.BindingContext = ToggleSwitch;
            MessageLabel.SetBinding(Label.IsVisibleProperty, "IsToggled", BindingMode.TwoWay);
            MessageButton.BindingContext = ToggleSwitch;
            MessageButton.SetBinding(Button.IsEnabledProperty, "IsToggled", BindingMode.TwoWay);
        }
Beispiel #44
0
 public MessageResult Show(string messageBoxText, string caption, MessageButton button, MessageResult defaultResult)
 {
     MessageBoxTest = messageBoxText;
     Caption        = caption;
     Button         = button;
     DefaultResult  = defaultResult;
     ShowCount++;
     return(Result);
 }
        static async Task<MessageResult> ShowMessageBox(string message, string caption, MessageButton button, MessageImage icon) {
            if (string.IsNullOrEmpty(message))
                throw new ArgumentNullException("message");
            if (icon != MessageImage.None)
                throw new NotSupportedException("Unfortunately, the default MessageBox class does not support setting an icon.");

            var messageBoxButton = TranslateMessageButton(button);
            var result = await MessageBox.ShowAsync(message, caption, messageBoxButton);
            return TranslateMessageBoxResult(result);
        }
 public Task<MessageResult> ShowAsync(string message, string caption = "",
     MessageButton button = MessageButton.Ok, MessageImage icon = MessageImage.None,
     MessageResult defaultResult = MessageResult.None, IDataContext context = null)
 {
     var tcs = new TaskCompletionSource<MessageResult>();
     if (_threadManager.IsUiThread)
         ShowMessage(message, caption, button, tcs);
     else
         _threadManager.InvokeOnUiThreadAsync(() => ShowMessage(message, caption, button, tcs));
     return tcs.Task;
 }
Beispiel #47
0
        public Task<MessageResult> ShowMessageAsync(string message, string caption, MessageButton button)
        {
            var tcs = new TaskCompletionSource<MessageResult>();

            CustomMessageBox messageBox = new CustomMessageBox()
            {
                Caption = caption,
                Message = message
            };

            switch (button)
            {
                case MessageButton.OK:
                    messageBox.LeftButtonContent = "OK";
                    messageBox.RightButtonContent = "Cancel";
                    break;
                case MessageButton.OKCancel:
                    messageBox.LeftButtonContent = "OK";
                    messageBox.RightButtonContent = "Cancel";
                    break;
                case MessageButton.YesNo:
                    messageBox.LeftButtonContent = "Yes";
                    messageBox.RightButtonContent = "No";
                    break;
                case MessageButton.YesNoCancel:
                    throw new NotImplementedException();
                default:
                    break;
            }

            MessageResult result = MessageResult.OK;

            messageBox.Dismissed += (s1, e1) =>
            {
                switch (e1.Result)
                {
                    case CustomMessageBoxResult.LeftButton:
                        break;
                    case CustomMessageBoxResult.RightButton:
                        result = MessageResult.Cancel;
                        break;
                    case CustomMessageBoxResult.None:
                        // Do something.
                        break;
                    default:
                        break;
                }

                tcs.SetResult(result);
            };

            messageBox.Show();
            return tcs.Task;
        }
Beispiel #48
0
        /// <summary>
		/// Translates the message button.
		/// </summary>
		/// <param name="button">The button.</param>
		/// <returns>
		/// Corresponding <see cref="MessageBoxButton"/>.
		/// </returns>
        protected static MessageBoxButton TranslateMessageButton(MessageButton button)
        {
            try
            {
                return Enum<MessageBoxButton>.ConvertFromOtherEnumValue(button);
            }
            catch (Exception)
            {
                throw new NotSupportedInSilverlightException("Unfortunately, the default MessageBox class of Silverlight does not support '{0}'", button);
            }
		}
 public Task<MessageResult> ShowAsync(string messageBoxText, string caption = "",
     MessageButton button = MessageButton.Ok, MessageImage icon = MessageImage.None,
     MessageResult defaultResult = MessageResult.None, IDataContext context = null)
 {
     if (_threadManager.IsUiThread)
         return ToolkitExtensions.FromResult(ShowMessage(messageBoxText, caption, button, icon, defaultResult));
     var tcs = new TaskCompletionSource<MessageResult>();
     _threadManager.InvokeOnUiThreadAsync(
         () => tcs.SetResult(ShowMessage(messageBoxText, caption, button, icon, defaultResult)));
     return tcs.Task;
 }
Beispiel #50
0
 /// <summary>
 /// Translates the message button.
 /// </summary>
 /// <param name="button">The button.</param>
 /// <returns>
 /// Corresponding <see cref="MessageBoxButton"/>.
 /// </returns>
 protected static MessageBoxButton TranslateMessageButton(MessageButton button)
 {
     try
     {
         return Enum<MessageBoxButton>.ConvertFromOtherEnumValue(button);
     }
     catch (Exception)
     {
         throw new NotSupportedInPlatformException("MessageBox class does not support MessageButton '{0}'", button);
     }
 }
        /// <summary>
        /// Shows the message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>The message result.</returns>
        /// <exception cref="ArgumentException">The <paramref name="message"/> is <c>null</c> or whitespace.</exception>
        protected virtual Task<MessageResult> ShowMessageBoxAsync(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
            Argument.IsNotNullOrWhitespace("message", message);

            return TaskHelper.Run(() =>
            {
                var messageBoxButton = TranslateMessageButton(button);
                var result = MessageBox.Show(message, caption, messageBoxButton);

                return TranslateMessageBoxResult(result);
            }, true);
        }
        /// <summary>
        /// Shows the message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>The message result.</returns>
        /// <exception cref="ArgumentException">The <paramref name="message"/> is <c>null</c> or whitespace.</exception>
        protected virtual Task<MessageResult> ShowMessageBox(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
            Argument.IsNotNullOrWhitespace("message", message);

            return Task.Factory.StartNew<MessageResult>(() =>
            {
                var messageBoxButton = TranslateMessageButton(button);
                var result = MessageBox.Show(message, caption, messageBoxButton);

                return TranslateMessageBoxResult(result);
            });
        }
        public MessageResultEventArgs(MessageButton button)
        {
            this.Button = button;

            if (button.Result is MessageResult)
            {
                this.Result = (MessageResult)button.Result;
            }
            else
            {
                this.Result = MessageResult.Other;
            }
        }
        private void ShowMessage(string messageBoxText, string caption, MessageButton button,
            MessageResult defaultResult,
            TaskCompletionSource<MessageResult> tcs)
        {
            var messageDialog = new MessageDialog(messageBoxText, caption);
            switch (button)
            {
                case MessageButton.Ok:
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Ok, tcs));
                    break;
                case MessageButton.OkCancel:
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Ok, tcs));
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Cancel, tcs));
                    break;
                case MessageButton.YesNo:
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Yes, tcs));
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.No, tcs));
                    break;
                case MessageButton.YesNoCancel:
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Yes, tcs));
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.No, tcs));
                    if (MvvmApplication.Current.Platform.Platform != PlatformType.WinPhone)
                        messageDialog.Commands.Add(CreateUiCommand(MessageResult.Cancel, tcs));
                    break;
                case MessageButton.AbortRetryIgnore:
                    if (MvvmApplication.Current.Platform.Platform == PlatformType.WinPhone)
                        throw ExceptionManager.EnumOutOfRange("button", button);

                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Abort, tcs));
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Retry, tcs));
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Ignore, tcs));
                    break;
                case MessageButton.RetryCancel:
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Retry, tcs));
                    messageDialog.Commands.Add(CreateUiCommand(MessageResult.Cancel, tcs));
                    break;
                default:
                    tcs.SetResult(MessageResult.None);
                    return;
            }
            for (int i = 0; i < messageDialog.Commands.Count; i++)
            {
                if (defaultResult == (MessageResult)messageDialog.Commands[i].Id)
                {
                    messageDialog.DefaultCommandIndex = (uint)i;
                    break;
                }
            }
            messageDialog.ShowAsync();
        }
Beispiel #55
0
        public MessageResult Show(string message, string caption, MessageButton button, MessageImage icon)
        {
            var vm = new DialogViewModel
            {
                Title = caption,
                Message = message,
                Buttons = button,
                Icon = icon
            };

            _windowManager.ShowDialog(vm);

            return vm.Result;
        }
Beispiel #56
0
        public MessageResult ShowMessage(string message, string caption, MessageButton button)
        {
            MessageBoxButton impButton = MessageBoxButton.OK;

            switch (button)
            {
                case MessageButton.OK:
                    impButton = MessageBoxButton.OK;
                    break;
                case MessageButton.OKCancel:
                    impButton = MessageBoxButton.OKCancel;
                    break;
                case MessageButton.YesNo:
                    impButton = MessageBoxButton.YesNo;
                    break;
                case MessageButton.YesNoCancel:
                    impButton = MessageBoxButton.YesNoCancel;
                    break;
                default:
                    break;
            }

            MessageBoxResult impResult = MessageBox.Show(message, caption, impButton);

            MessageResult result = MessageResult.OK;

            switch (impResult)
            {
                case MessageBoxResult.Cancel:
                    result = MessageResult.Cancel;
                    break;
                case MessageBoxResult.No:
                    result = MessageResult.No;
                    break;
                case MessageBoxResult.None:
                    result = MessageResult.None;
                    break;
                case MessageBoxResult.OK:
                    result = MessageResult.OK;
                    break;
                case MessageBoxResult.Yes:
                    result = MessageResult.Yes;
                    break;
                default:
                    break;
            }

            return result;
        }
        /// <summary>
        /// Shows the specified message and allows to await for the message to complete.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>A Task containing the <see cref="MessageResult"/>.</returns>
        public Task<MessageResult> ShowAsync(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None) {
#if WinRT
            return ShowMessageBox(message, caption, button, icon);
#else
            var taskSource = new TaskCompletionSource<MessageResult>();
            try {
                var result = ShowMessageBox(message, caption, button, icon);
                taskSource.SetResult(result);
            }
            catch (Exception ex) {
                taskSource.SetException(ex);
            }
            return taskSource.Task;
#endif
        }
Beispiel #58
0
    public FormWithButton()
    {
        Text = "Form With Button";
        Button btn = new Button();
        btn.Parent = this;
        btn.Location = new Point(50,25);
        btn.AutoSize = true;
        btn.Text = CLICKME;
        btn.Click += ButtonOnClick;

        mbtn = new MessageButton();
        mbtn.Parent = this;
        mbtn.Location = new Point(50,50);
        mbtn.AutoSize = true;
        mbtn.Text = "My Message Button";

    }
Beispiel #59
0
        /// <summary>
        /// Shows the message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>The message result.</returns>
        /// <exception cref="ArgumentException">The <paramref name="message"/> is <c>null</c> or whitespace.</exception>
        protected virtual Task<MessageResult> ShowMessageBox(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
            Argument.IsNotNullOrWhitespace("message", message);

            var tcs = new TaskCompletionSource<MessageResult>();

            _dispatcherService.BeginInvoke(() =>
            {
                MessageBoxResult result;
                var messageBoxButton = TranslateMessageButton(button);

                result = MessageBox.Show(message, caption, messageBoxButton);

                tcs.SetResult(TranslateMessageBoxResult(result));
            });

            return tcs.Task;
        }
        /// <summary>
        ///     Shows the message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="button">The button.</param>
        /// <param name="icon">The icon.</param>
        /// <returns>The message result.</returns>
        /// <exception cref="ArgumentException">The <paramref name="message" /> is <c>null</c> or whitespace.</exception>
        protected virtual async Task<MessageResult> ShowMessageBoxAsync(string message, string caption = "", MessageButton button = MessageButton.OK, MessageImage icon = MessageImage.None)
        {
            if (!_configurationResultMap.ContainsKey(button))
            {
                throw new ArgumentOutOfRangeException("button");
            }

            var messageResult = MessageResult.None;

            var currentPage = Application.Current.CurrentPage();
            if (currentPage != null)
            {
                var configuration = _configurationResultMap[button];
                var result = Xamarin.Forms.MessagingCenter.SendAlert(currentPage, caption, message, configuration.PositiveButton, configuration.NegativeButton);
                await result.Task;
                messageResult = result.Task.Result ? configuration.PositiveResult: configuration.NegativeResult;
            }

            return messageResult;
        }