开发者

Button, IInvokeProvider and Click

I'm just trying 开发者_如何学编程to figure this one out. Why does the button IInvokeProvider call the click event without doing any explicit setting? What if I wanted to automate another method like MouseEnter or MouseLeave? And what makes it assume that when you call the Invoke() method it should do the Click event?

This is my code:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    ButtonAutomationPeer buttonPeer = new ButtonAutomationPeer(button);
    IInvokeProvider invokeProvider = buttonPeer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
    invokeProvider.Invoke(); // this triggers button_Click handler
}

private void button_Click(object sender, RoutedEventArgs e)
{
    MessageBox.Show("Button clicked!");
}

Thanks!


The IInvokeProvider interface is part of the System.Windows.Automation family of namespaces also referred to as WUIA (Windows User Interface Automation). WUIA is meant to support accessibility clients (screen readers and the like) to support for example blind users. The IInvokeProvider.Invoke() method is invoking the default action on the implementing UI element. In your case the default action on a button is the click event.

You will have to invoke Mouse events using a different interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜