How to programmatically click an ApplicationBarIconButton?

Viewed 458

So that's the question. I have the following variants of code in my test framework (assuming appBarButton is ApplicationBarIconButton):

var bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic;
var method = typeof(ApplicationBarIconButton)
             .GetMethod("ClickEvent", bindingFlags);

if (method != null)
{
    method.Invoke(appBarButton, null);
}

or

IInvokeProvider invokableButton;
var isInvokable = (invokableButton = appBarButton as IInvokeProvider) != null;
if (isInvokable)
{
    invokableButton.Invoke();
}

Both pieces are not working. So I want to find some workarounds to programmatically click the ApplicationBarIconButton. Any help?

1 Answers
Related