本文整理汇总了C#中MessageBoxButton.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# MessageBoxButton.HasFlag方法的具体用法?C# MessageBoxButton.HasFlag怎么用?C# MessageBoxButton.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageBoxButton
的用法示例。
在下文中一共展示了MessageBoxButton.HasFlag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowAsync
public static async Task<MessageBoxResult> ShowAsync ( string messageBoxText,
string caption,
MessageBoxButton button )
{
MessageDialog md = new MessageDialog ( messageBoxText, caption );
MessageBoxResult result = MessageBoxResult.None;
if ( button.HasFlag ( MessageBoxButton.OK ) )
{
md.Commands.Add ( new UICommand ( "OK",
new UICommandInvokedHandler ( ( cmd ) => result = MessageBoxResult.OK ) ) );
}
if ( button.HasFlag ( MessageBoxButton.Yes ) )
{
md.Commands.Add ( new UICommand ( "Yes",
new UICommandInvokedHandler ( ( cmd ) => result = MessageBoxResult.Yes ) ) );
}
if ( button.HasFlag ( MessageBoxButton.No ) )
{
md.Commands.Add ( new UICommand ( "No",
new UICommandInvokedHandler ( ( cmd ) => result = MessageBoxResult.No ) ) );
}
if ( button.HasFlag ( MessageBoxButton.Cancel ) )
{
md.Commands.Add ( new UICommand ( "Cancel",
new UICommandInvokedHandler ( ( cmd ) => result = MessageBoxResult.Cancel ) ) );
md.CancelCommandIndex = ( uint ) md.Commands.Count - 1;
}
var op = await md.ShowAsync ();
return result;
}
示例2: ShowAsync
public static async Task<MessageBoxResult> ShowAsync(string messageBoxText,
string caption,
MessageBoxButton button = MessageBoxButton.Ok)
{
var result = MessageBoxResult.None;
var md = new MessageDialog(messageBoxText, caption);
if (button.HasFlag(MessageBoxButton.Ok))
{
md.Commands.Add(new UICommand("OK",
cmd => result = MessageBoxResult.Ok));
}
if (button.HasFlag(MessageBoxButton.Yes))
{
md.Commands.Add(new UICommand("Yes",
cmd => result = MessageBoxResult.Yes));
}
if (button.HasFlag(MessageBoxButton.No))
{
md.Commands.Add(new UICommand("No",
cmd => result = MessageBoxResult.No));
}
if (button.HasFlag(MessageBoxButton.Cancel))
{
md.Commands.Add(new UICommand("Cancel",
cmd => result = MessageBoxResult.Cancel));
md.CancelCommandIndex = (uint) md.Commands.Count - 1;
}
try
{
await md.ShowAsync();
}
catch (UnauthorizedAccessException) { }
return result;
}
示例3: ShowAsync
public static async Task<MessageBoxResult> ShowAsync(string messageBoxText,
string caption,
MessageBoxButton button)
{
var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
var result = MessageBoxResult.None;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal,
async () =>
{
var md = new MessageDialog(messageBoxText, caption);
if (button.HasFlag(MessageBoxButton.Ok))
{
md.Commands.Add(new UICommand("OK",
cmd => result = MessageBoxResult.Ok));
}
if (button.HasFlag(MessageBoxButton.Yes))
{
md.Commands.Add(new UICommand("Yes",
cmd => result = MessageBoxResult.Yes));
}
if (button.HasFlag(MessageBoxButton.No))
{
md.Commands.Add(new UICommand("No",
cmd => result = MessageBoxResult.No));
}
if (button.HasFlag(MessageBoxButton.Cancel))
{
md.Commands.Add(new UICommand("Cancel",
cmd => result = MessageBoxResult.Cancel));
md.CancelCommandIndex = (uint) md.Commands.Count - 1;
}
await md.ShowAsync();
});
return result;
}