1. <i id='E2dlh'><tr id='E2dlh'><dt id='E2dlh'><q id='E2dlh'><span id='E2dlh'><b id='E2dlh'><form id='E2dlh'><ins id='E2dlh'></ins><ul id='E2dlh'></ul><sub id='E2dlh'></sub></form><legend id='E2dlh'></legend><bdo id='E2dlh'><pre id='E2dlh'><center id='E2dlh'></center></pre></bdo></b><th id='E2dlh'></th></span></q></dt></tr></i><div id='E2dlh'><tfoot id='E2dlh'></tfoot><dl id='E2dlh'><fieldset id='E2dlh'></fieldset></dl></div>
    2. <small id='E2dlh'></small><noframes id='E2dlh'>

      <legend id='E2dlh'><style id='E2dlh'><dir id='E2dlh'><q id='E2dlh'></q></dir></style></legend>
        <bdo id='E2dlh'></bdo><ul id='E2dlh'></ul>

    3. <tfoot id='E2dlh'></tfoot>
    4. UIElement.AddHandler() 与 .Event += 定义

      时间:2023-09-15

        <small id='QrGKK'></small><noframes id='QrGKK'>

        • <legend id='QrGKK'><style id='QrGKK'><dir id='QrGKK'><q id='QrGKK'></q></dir></style></legend>
            <tbody id='QrGKK'></tbody>
            <bdo id='QrGKK'></bdo><ul id='QrGKK'></ul>

                <tfoot id='QrGKK'></tfoot>
                <i id='QrGKK'><tr id='QrGKK'><dt id='QrGKK'><q id='QrGKK'><span id='QrGKK'><b id='QrGKK'><form id='QrGKK'><ins id='QrGKK'></ins><ul id='QrGKK'></ul><sub id='QrGKK'></sub></form><legend id='QrGKK'></legend><bdo id='QrGKK'><pre id='QrGKK'><center id='QrGKK'></center></pre></bdo></b><th id='QrGKK'></th></span></q></dt></tr></i><div id='QrGKK'><tfoot id='QrGKK'></tfoot><dl id='QrGKK'><fieldset id='QrGKK'></fieldset></dl></div>

                本文介绍了UIElement.AddHandler() 与 .Event += 定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                问题的第一部分:这两个事件注册有什么区别?

                1.st part of the quesion: What is the difference between these 2 event registrations ?

                _popUp.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(PopUp_PreviewMouseLeftButtonDown));
                
                _popUp.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(_popUp_PreviewMouseLeftButtonDown);
                

                问题的第二部分:或最终与

                popUp.Opened += PopUp_Opened;
                

                推荐答案

                根据Redgate的Reflector,没有区别.这两种方法最终都会调用内部方法EventHandlerStore.AddRoutedEventHandler.这是 PreviewMouseLeftButtonDown 事件的 add 访问器的反射器输出(在类 UIElement 中):

                According to Redgate's Reflector, there is no difference. Both methods eventually call the internal method EventHandlerStore.AddRoutedEventHandler. This is the reflector output of the add accessor for the PreviewMouseLeftButtonDown event (in the class UIElement):

                public void add_PreviewMouseLeftButtonDown(MouseButtonEventHandler value)
                {
                    this.AddHandler(PreviewMouseLeftButtonDownEvent, value, false);
                }
                

                如您所见,它会为您调用 UIElement.AddHandler.

                As you can see it calls UIElement.AddHandler for you.

                在编辑问题之前,您询问的是弹出窗口的 Opened 事件.在这种情况下,有一个区别:首先,Opened事件不是作为路由事件实现的,而是作为一个简单事件实现的,所以你甚至不能使用AddHandler打电话给它.其次,反射器显示在 EventHandlerStore 中调用了一个不同的方法,它将处理程序添加到一个简单的委托集合中.

                Before you edited your question you were asking about the Opened event of the popup. In that case, there is a difference: First, the Opened event is not implemented as a routed event but as a simple event, so you can't even use the AddHandler call on it. Secondly, the reflector shows that a different method is called in the EventHandlerStore which adds the handler to a simple delegate collection.

                这篇关于UIElement.AddHandler() 与 .Event += 定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:为什么不使用自定义类而不是继承 EventArgs 类 下一篇:如何修复事件延迟

                相关文章

              • <small id='xkgnx'></small><noframes id='xkgnx'>

                  <bdo id='xkgnx'></bdo><ul id='xkgnx'></ul>
                <i id='xkgnx'><tr id='xkgnx'><dt id='xkgnx'><q id='xkgnx'><span id='xkgnx'><b id='xkgnx'><form id='xkgnx'><ins id='xkgnx'></ins><ul id='xkgnx'></ul><sub id='xkgnx'></sub></form><legend id='xkgnx'></legend><bdo id='xkgnx'><pre id='xkgnx'><center id='xkgnx'></center></pre></bdo></b><th id='xkgnx'></th></span></q></dt></tr></i><div id='xkgnx'><tfoot id='xkgnx'></tfoot><dl id='xkgnx'><fieldset id='xkgnx'></fieldset></dl></div>

                  <legend id='xkgnx'><style id='xkgnx'><dir id='xkgnx'><q id='xkgnx'></q></dir></style></legend>

                    <tfoot id='xkgnx'></tfoot>