我有这段代码:
async private void InformUserOfRenameOption(string platypusName)
{
CoreWindowDialog cwd = new CoreWindowDialog(String.Format(
"This platypus has been given the default name {0}. Do you want to change it?", platypusName));
cwd.Commands.Add(new UICommand { Label = "Yes", Id = 0 });
cwd.Commands.Add(new UICommand { Label = "No", Id = 1 });
cwd.Commands.Add(new UICommand { Label = "Cancel", Id = 2 });
cwd.CancelCommandIndex = 2;
IUICommand cmd = await cwd.ShowAsync();
//if (cmd.Id == 0) <= 'Operator '==' cannot be applied to operands of type 'object' and 'int'
if (Convert.ToInt32(cmd.Id) == 0)
{
appbarbtnRenamePlatypus.Tapped();
}
}
...但是我以编程方式点击AppBarButton的尝试因编译时错误而失败:&#34; 事件&#39; Windows.UI.Xaml.UIElement.Tapped&#39;只能出现在+ =或 - = &#34;
的左侧那么如何我以编程方式点击按钮,或者更具体地说,让它的Button.Flyout Flyout飞出来?
答案 0 :(得分:2)
通常,您会将AppBar按钮的单击处理程序中的代码重构为自己的方法,然后您可以从任何地方调用它。
如果您感觉更冒险,也可以考虑使用ICommand
- 这使您可以拥有任意数量的UI元素(例如ButtonBase.Command
)或直接从代码中调用它。