【发布时间】:2015-01-04 14:18:17
【问题描述】:
我有这个代码:
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 失败并出现编译时错误:“事件 'Windows.UI.Xaml.UIElement.Tapped' 只能出现在 += 的左侧或 -="
那么如何我以编程方式点击按钮,或者更具体地说,让它的 Button.Flyout Flyout 飞出?
【问题讨论】:
-
我相信你可以使用Automation Peers。或者您可以创建一个从
AppBarButton扩展的自定义控件,因为它不是sealed。
标签: c# windows-runtime appbar winrt-component