本文整理匯總了C#中Windows.UI.Popups.UICommand.Invoked方法的典型用法代碼示例。如果您正苦於以下問題:C# UICommand.Invoked方法的具體用法?C# UICommand.Invoked怎麽用?C# UICommand.Invoked使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Windows.UI.Popups.UICommand
的用法示例。
在下文中一共展示了UICommand.Invoked方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ShowAsync
public static async Task<Result> ShowAsync(
string content
, string caption
, UICommand yesCommand
, UICommand noCommand = null
, UICommand cancelCommand = null
)
{
var dialog = new MessageDialog(content);
dialog.Options = MessageDialogOptions.None;
dialog.Title = caption;
dialog.Commands.Add(yesCommand);
dialog.DefaultCommandIndex = 0;
dialog.CancelCommandIndex = 0;
if (noCommand != null)
{
dialog.Commands.Add(noCommand);
dialog.CancelCommandIndex = (uint)dialog.Commands.Count - 1;
}
if (cancelCommand != null)
{
// Devices with a hardware back button
// use the hardware button for Cancel.
// for other devices, show a third option
if (ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
{
// disable the default Cancel command index
// so that dialog.ShowAsync() returns null
// in that case
dialog.CancelCommandIndex = UInt32.MaxValue;
}
else
{
dialog.Commands.Add(cancelCommand);
dialog.CancelCommandIndex = (uint)dialog.Commands.Count - 1;
}
}
var command = await dialog.ShowAsync();
if (command == null && cancelCommand != null)
{
// back button was pressed
// invoke the UICommand
cancelCommand.Invoked(cancelCommand);
return Result.Cancel;
}
if (command == yesCommand)
return Result.Yes;
else if (command == noCommand)
return Result.No;
return Result.Cancel;
}