本文整理匯總了C#中Windows.UI.Popups.UICommand類的典型用法代碼示例。如果您正苦於以下問題:C# UICommand類的具體用法?C# UICommand怎麽用?C# UICommand使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UICommand類屬於Windows.UI.Popups命名空間,在下文中一共展示了UICommand類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: OnTapped
private async void OnTapped(object sender, TappedRoutedEventArgs e)
{
TextBlock tb = sender as TextBlock;
PopupMenu menu = new PopupMenu();
UICommandInvokedHandler invokedHandler = (cmd) =>
{
SolidColorBrush brush = cmd.Id as SolidColorBrush;
tb.Foreground = brush;
};
UICommand cmdRed = new UICommand("紅", invokedHandler, new SolidColorBrush(Colors.Red));
UICommand cmdOrange = new UICommand("橙", invokedHandler, new SolidColorBrush(Colors.Orange));
UICommand cmdPurple = new UICommand("紫", invokedHandler, new SolidColorBrush(Colors.Purple));
menu.Commands.Add(cmdRed);
menu.Commands.Add(cmdOrange);
menu.Commands.Add(cmdPurple);
GeneralTransform gt = tb.TransformToVisual(null);
Point popupPoint = gt.TransformPoint(new Point(0d, tb.ActualHeight));
await menu.ShowAsync(popupPoint);
}
示例2: Notify
public async virtual Task Notify(string message, string title, string primaryOptionText, string secondaryOptionText, Action primaryOptionAction = null, Action secondaryOptionAction = null)
{
if(Application.Current.Resources.ContainsKey(message))
message = (string) Application.Current.Resources[message];
if(Application.Current.Resources.ContainsKey(title))
title = (string) Application.Current.Resources[title];
var dialog = new MessageDialog(message, title);
if (!string.IsNullOrEmpty(primaryOptionText))
{
primaryOptionText = (string) Application.Current.Resources[primaryOptionText];
var command = new UICommand(primaryOptionText);
if (primaryOptionAction != null) command.Invoked = uiCommand => primaryOptionAction();
dialog.Commands.Add(command);
}
if (!string.IsNullOrEmpty(secondaryOptionText))
{
secondaryOptionText = (string)Application.Current.Resources[secondaryOptionText];
var command = new UICommand(secondaryOptionText);
if (secondaryOptionAction != null) command.Invoked = uiCommand => secondaryOptionAction();
dialog.Commands.Add(command);
}
await dialog.ShowAsync();
}
示例3: ShowMessage
public virtual void ShowMessage(string title, UICommand alternative1)
{
var messageDialog = new MessageDialog(title);
messageDialog.Commands.Add(alternative1);
messageDialog.CancelCommandIndex = 0;
messageDialog.ShowAsync();
}
示例4: OnGameStartQuestions
public async void OnGameStartQuestions()
{
{
var dialog = new MessageDialog("Would you like to play with real player or computer?", "Starting a new game");
var cmdOpt1 = new UICommand("player vs player", cmd => GameManager.SetPvP(), 1);
var cmdOpt2 = new UICommand("player vs computer", cmd => GameManager.SetPvAI(), 2);
dialog.Commands.Add(cmdOpt1);
dialog.Commands.Add(cmdOpt2);
dialog.DefaultCommandIndex = 0;
await dialog.ShowAsync();
}
if (GameManager.IsGameVersusAI)
{
var dialog = new MessageDialog("Select the color of your pieces.\n(Darker coloured pieces moves first)", "Color");
var cmdOpt1 = new UICommand("dark", cmd => GameManager.SetPlayerBlack(), 1);
var cmdOpt2 = new UICommand("light", cmd => GameManager.SetPlayerWhite(), 2);
dialog.Commands.Add(cmdOpt1);
dialog.Commands.Add(cmdOpt2);
dialog.DefaultCommandIndex = 0;
await dialog.ShowAsync();
}
GameManager.Start();
}
示例5: HardwareButtons_BackPressed
private async void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
//獲取當前的激活的窗口的框架
Frame frame = Window.Current.Content as Frame;
//判斷是否為空,是否能返回,其實就是主頁麵了,主頁麵肯定不能返回嘛
if (null != frame && (!frame.CanGoBack))
{
//設置事件已經處理
e.Handled = true;
//設置在最後一個界麵跳出彈出窗口
var messageDig = new MessageDialog("確定退出嗎?");
var btn_OK = new UICommand("確定");
var btn_NO = new UICommand("取消");
messageDig.Commands.Add(btn_OK);
messageDig.Commands.Add(btn_NO);
//展示窗口,獲取按鈕是否退出
var result = await messageDig.ShowAsync();
//如果是確定退出就直接讓應用程序退出
if (null != result && result.Label == "確定")
{
Application.Current.Exit();
}
}
//如果可以返回,就返回上一個界麵
else if (frame.CanGoBack)
{
frame.GoBack();
e.Handled = true;
}
}
示例6: validateName
public void validateName(object sender, RoutedEventArgs e)
{
// Check to make sure the name isn't blank or already used then change to first button to train screen
device_name = device_name_text.Text;
DeviceManager m = ((App)(CPRemoteApp.App.Current)).deviceController;
if(device_name.TrimStart(' ').Length == 0)
{
MessageDialog msgDialog = new MessageDialog("Please enter a valid name for the device! The device's name cannot be empty!", "Whoops!");
UICommand okBtn = new UICommand("OK");
okBtn.Invoked += delegate { };
msgDialog.Commands.Add(okBtn);
msgDialog.ShowAsync();
return;
}
else if (channel_or_volume)
{
foreach (VolumeDevice d in m.getVolumeDevices())
{
if (d.get_name() == device_name)
{
MessageDialog msgDialog = new MessageDialog("There is already a volume device saved with that name! Please enter a unique name for the device!", "Whoops!");
UICommand okBtn = new UICommand("OK");
okBtn.Invoked += delegate { };
msgDialog.Commands.Add(okBtn);
msgDialog.ShowAsync();
return;
}
}
}
else
{
foreach (ChannelDevice d in m.getChannelDevices())
{
if (d.get_name() == device_name)
{
MessageDialog msgDialog = new MessageDialog("There is already a channel device saved with that name! Please enter a unique name for the device!", "Whoops!");
UICommand okBtn = new UICommand("OK");
okBtn.Invoked += delegate { };
msgDialog.Commands.Add(okBtn);
msgDialog.ShowAsync();
return;
}
}
}
device_name_text.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
device_name_block.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
next_button.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
if (channel_or_volume)
{
trainVolumeDevice();
}
else
{
// Start at train Zero and Populate all of the IR information, via next button clicks
trainZero();
}
}
示例7: RunAsync
public async Task<bool> RunAsync()
{
Telemetry.Client.TrackTrace("Startup Workflow - Begin");
var authenticatedSilently = await SecurityManager.TryAuthenticateSilently();
if (!authenticatedSilently)
{
Telemetry.Client.TrackTrace("Startup Workflow - Authentication required.");
if (!frame.Navigate(typeof(LoginPage), arguments))
{
throw new Exception("Failed to create login page");
}
bool authenticated = false;
while (!authenticated)
{
authenticated = await SecurityManager.Authenticate();
if (!authenticated)
{
Telemetry.Client.TrackTrace("Startup Workflow - Authentication failed. Asking user to retry.");
var resourceManager = CompositionManager.Current.GetInstance<IStringResourceManager>();
var messageTitle = resourceManager.GetString("LoginRequiredMessageTitle");
var messageText = resourceManager.GetString("LoginRequiredMessageText");
var dialog = new MessageDialog(messageText, messageTitle);
var okCommand = new UICommand(resourceManager.GetString("LoginFailedRetry"));
var cancelCommand = new UICommand(resourceManager.GetString("LoginFailedCancelAndExit"));
dialog.Commands.Add(okCommand);
dialog.Commands.Add(cancelCommand);
var dialogResult = await dialog.ShowAsync();
if (dialogResult == cancelCommand)
{
Telemetry.Client.TrackTrace("Startup Workflow - Authentication failed. User declined to retry.", TelemetrySeverityLevel.Warning);
return false;
}
}
}
}
Telemetry.Client.TrackTrace("Startup Workflow - Authentication successful. Redirecting to the main page.");
if (!frame.Navigate(typeof(MainPage), arguments))
{
throw new Exception("Failed to create initial page");
}
return true;
}
示例8: showExitConfirmation
private async void showExitConfirmation()
{
var msg = new MessageDialog(EXIT_CONFIRMATION_TEXT, EXIT_CONFIRMATION_TITLE);
var okBtn = new UICommand("Exit", new UICommandInvokedHandler(ConfirmationCommandHandler));
var cancelBtn = new UICommand("Cancel", new UICommandInvokedHandler(ConfirmationCommandHandler));
msg.Commands.Add(okBtn);
msg.Commands.Add(cancelBtn);
IUICommand result = await msg.ShowAsync();
}
示例9: showSaveConfirmation
private async void showSaveConfirmation()
{
var msg = new MessageDialog(SAVE_CONFIRMATION_TEXT, SAVE_CONFIRMATION_TITLE);
var okBtn = new UICommand(FINISH, new UICommandInvokedHandler(SaveConfirmationCommandHandler));
var cancelBtn = new UICommand(CANCEL, new UICommandInvokedHandler(SaveConfirmationCommandHandler));
msg.Commands.Add(okBtn);
msg.Commands.Add(cancelBtn);
IUICommand result = await msg.ShowAsync();
}
示例10: ShowError
private void ShowError(Exception exception)
{
UICommand okCommand = new UICommand("OK", (cmd) =>
{
Messenger.Default.Send<StartNewGameMessage>(new StartNewGameMessage());
}, 1);
ShowMessage("Error loading game", exception.Message, new UICommand[] { okCommand });
}
示例11: OnClick
private async void OnClick(object sender, RoutedEventArgs e)
{
MessageDialog dlg = new MessageDialog("確定要執行任務嗎", "提示");
UICommand cmdok = new UICommand("確定", new UICommandInvokedHandler(OnCommandAct), 1);
UICommand cmdcancel = new UICommand("取消", new UICommandInvokedHandler(OnCommandAct), 2);
dlg.Commands.Add(cmdok);
dlg.Commands.Add(cmdcancel);
await dlg.ShowAsync();
}
示例12: ShowMessage
private async void ShowMessage(string title, string content, UICommand[] commands)
{
var dialog = new MessageDialog(content, title);
foreach (var command in commands)
{
dialog.Commands.Add(command);
}
await dialog.ShowAsync();
}
示例13: AddButton
/// <summary>
/// Adds a button to the MessageDialog with given caption and action.
/// </summary>
/// <param name="dialog"></param>
/// <param name="caption"></param>
/// <param name="action"></param>
public static void AddButton(this MessageDialog dialog, string caption, Action action)
{
var cmd = new UICommand(
caption,
c =>
{
if (action != null)
action.Invoke();
});
dialog.Commands.Add(cmd);
}
示例14: AddCommand
/// <summary>
/// 添加一個命令到對話框。
/// </summary>
/// <param name="dialog">對話框。</param>
/// <param name="label">命令文本。</param>
/// <param name="action">命令動作。</param>
/// <returns>對話框。</returns>
/// <exception cref="ArgumentNullException"><c>dialog</c> 為空。</exception>
public static MessageDialog AddCommand(this MessageDialog dialog, string label, Action action)
{
if (dialog == null)
{
throw new ArgumentNullException(nameof(dialog));
}
UICommand command = new UICommand(label, commandAction => action?.Invoke());
dialog.Commands.Add(command);
return dialog;
}
示例15: PromptForMediaPack
/// <summary>
/// Prompts the user to install the Media Feature Pack.
/// </summary>
/// <returns>An awaitable task that returns when the prompt has completed.</returns>
public static async Task PromptForMediaPack()
{
var messageDialog = new MessageDialog(MediaPlayer.GetResourceString("MediaFeaturePackRequiredLabel"), MediaPlayer.GetResourceString("MediaFeaturePackRequiredText"));
var cmdDownload = new UICommand(MediaPlayer.GetResourceString("MediaFeaturePackDownloadLabel"));
var cmdCancel = new UICommand(MediaPlayer.GetResourceString("MediaFeaturePackCancelLabel"));
messageDialog.Commands.Add(cmdDownload);
messageDialog.Commands.Add(cmdCancel);
var cmd = await messageDialog.ShowAsync();
if (cmd == cmdDownload)
{
await Launcher.LaunchUriAsync(MediaPackUri);
}
}