【发布时间】:2014-01-08 04:45:42
【问题描述】:
这就是问题所在。我的测试框架中有以下代码变体(假设 appBarButton 是 ApplicationBarIconButton):
var bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic;
var method = typeof(ApplicationBarIconButton)
.GetMethod("ClickEvent", bindingFlags);
if (method != null)
{
method.Invoke(appBarButton, null);
}
或
IInvokeProvider invokableButton;
var isInvokable = (invokableButton = appBarButton as IInvokeProvider) != null;
if (isInvokable)
{
invokableButton.Invoke();
}
这两个部分都不起作用。所以我想找到一些解决方法来以编程方式单击 ApplicationBarIconButton。有什么帮助吗?
【问题讨论】:
-
抱歉,我不明白以编程方式执行点击的原因。为什么不升事件或者调用点击事件调用的de方法呢?
-
我想扩展现有的测试框架(link)来自动化一些步骤。在涉及 AppBar 的某些情况下,该框架似乎表现不正确。
-
啊,好的,我明白了。不知道有没有可能,因为 AppBar 是由 PhoneApplicationPage 类公开,由 Phone Shell 管理的。
-
你不能这样做,因为 Click 是一个事件处理程序并且只暴露了添加/删除。您可以创建一个 ApplicationBarManager 来处理按钮的创建并保留已注册处理程序的日志,但这对我来说似乎是错误的!
标签: c# windows-phone-8 windows-phone appbar