• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MessageButton类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MessageButton的典型用法代码示例。如果您正苦于以下问题:C# MessageButton类的具体用法?C# MessageButton怎么用?C# MessageButton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MessageButton类属于命名空间,在下文中一共展示了MessageButton类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ShowMessageBox

        /// <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);
        }
开发者ID:justdude,项目名称:DbExport,代码行数:41,代码来源:MessageService.winrt.cs


示例2: SessionMessage

 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;
 }
开发者ID:jmptrader,项目名称:WebFrameworkMVC,代码行数:35,代码来源:SessionMessage.cs


示例3: Show

        /// <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
        }
开发者ID:Geminior,项目名称:Caliburn.Micro.Extras,代码行数:15,代码来源:MessageService.cs


示例4: ShowMessage

 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);
 }
开发者ID:sami1971,项目名称:MugenMvvmToolkit,代码行数:7,代码来源:MessagePresenter.cs


示例5: ShowAsync

        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;
        }
开发者ID:WildGums,项目名称:Orchestra,代码行数:32,代码来源:MessageService.cs


示例6: GetAsText

        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);
        }
开发者ID:WildGums,项目名称:Orchestra,代码行数:28,代码来源:IMessageServiceExtensions.cs


示例7: TextMessage

		public TextMessage(string text, string title, MessageButton button)
		{
			Text = text;
			Title = title;
			Button = button;
			Result = MessageResult.OK;
		}
开发者ID:yukiyuki,项目名称:MyToolkit,代码行数:7,代码来源:TextMessage.cs


示例8: ShowMessageBoxAsync

        /// <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;
        }
开发者ID:matthijskoopman,项目名称:Catel,代码行数:36,代码来源:MessageService.wpf.cs


示例9:

 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();
 }
开发者ID:LINDAIS,项目名称:DevExpress.Mvvm.Free,代码行数:7,代码来源:MessageBoxService.cs


示例10: ShowMessageBoxAsync

        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();
            }
        }
开发者ID:bulanh,项目名称:Orchestra,代码行数:59,代码来源:MahAppsMessageService.cs


示例11: Show

 public MessageResult Show(string messageBoxText, string caption, MessageButton button, MessageResult defaultResult) {
     MessageBoxTest = messageBoxText;
     Caption = caption;
     Button = button;
     DefaultResult = defaultResult;
     ShowCount++;
     return Result;
 }
开发者ID:LINDAIS,项目名称:DevExpress.Mvvm.Free,代码行数:8,代码来源:ConfirmationBehaviorTests.cs


示例12: ShowMessage

        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
        }
开发者ID:LINDAIS,项目名称:DevExpress.Mvvm.Free,代码行数:8,代码来源:MessageBoxServiceExtensions.cs


示例13: TranslateMessageButton

 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));
     }
 }
开发者ID:Geminior,项目名称:Caliburn.Micro.Extras,代码行数:9,代码来源:MessageService.cs


示例14: ShowDialogAsync

 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);
     });
 }
开发者ID:jbatman,项目名称:XPlatformCloudKit,代码行数:9,代码来源:MessageService.cs


示例15: ShowMessageBox

        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);
        }
开发者ID:Geminior,项目名称:Caliburn.Micro.Extras,代码行数:10,代码来源:MessageService.cs


示例16: ShowMessageAsync

        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;
        }
开发者ID:roosi,项目名称:done,代码行数:54,代码来源:DialogService.cs


示例17: ShowAsync

 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;
 }
开发者ID:sami1971,项目名称:MugenMvvmToolkit,代码行数:11,代码来源:MessagePresenter.cs


示例18: TranslateMessageButton

        /// <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);
            }
		}
开发者ID:pars87,项目名称:Catel,代码行数:18,代码来源:MessageService.cs


示例19: TranslateMessageButton

 /// <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);
     }
 }
开发者ID:Catel,项目名称:Catel,代码行数:18,代码来源:MessageService.cs


示例20: ShowAsync

 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;
 }
开发者ID:dbeattie71,项目名称:MugenMvvmToolkit,代码行数:11,代码来源:MessagePresenter.cs



注:本文中的MessageButton类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MessageCollection类代码示例发布时间:2022-05-24
下一篇:
C# MessageBusType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap