本文整理汇总了C#中MessageButton类的典型用法代码示例。如果您正苦于以下问题:C# MessageButton类的具体用法?C# MessageButton怎么用?C# MessageButton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageButton类属于命名空间,在下文中一共展示了MessageButton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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
}
示例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);
}
示例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;
}
示例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);
}
示例7: TextMessage
public TextMessage(string text, string title, MessageButton button)
{
Text = text;
Title = title;
Button = button;
Result = MessageResult.OK;
}
示例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;
}
示例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();
}
示例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();
}
}
示例11: Show
public MessageResult Show(string messageBoxText, string caption, MessageButton button, MessageResult defaultResult) {
MessageBoxTest = messageBoxText;
Caption = caption;
Button = button;
DefaultResult = defaultResult;
ShowCount++;
return Result;
}
示例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
}
示例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));
}
}
示例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);
});
}
示例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);
}