随笔-123  评论-297  文章-2  trackbacks-13

    通过程序触发元素的事件有两种方法,一种是通过系统的Automation,另外一种是通过元素的RaiseEvent方法。
    现在举例说明以上两种方法的用法,以触发按钮的Click事件为例:
    
     Automation

     ButtonAutomationPeer peer = new ButtonAutomationPeer( someButton );
     IInvokeProvider invokeProv =peer.GetPattern( PatternInterface.Invoke )  as IInvokeProvider;
     invokeProv.Invoke();


     RaiseEvent

      someButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));


     那么两种方法有什么区别或者说优劣吗?

    Automation在元素为disabled状态下会发生异常,而RaiseEvent则可以正常调用

    原文:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1329603&SiteID=1


posted on 2007-07-02 17:32 stswordman 阅读(426) 评论(0)  编辑 收藏 网摘 所属分类: WPF



发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 803364




相关文章:

相关链接: