【问题标题】:Visual Studio 2010 add in - events not triggeredVisual Studio 2010 插件 - 未触发事件
【发布时间】:2011-03-01 16:29:07
【问题描述】:

我编写了一个将活动文档作为参数的插件。所以每次活动文档发生变化时,我都需要知道。为此,我想使用 DTE2 对象的“Events.DocumentEvents.DocumentOpened”事件。但问题是即使我更改了活动文档,事件也永远不会被触发。

sn-p代码如下

        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        _applicationObject = (DTE2)application;

        _applicationObject.Events.DocumentEvents.DocumentOpened += new _dispDocumentEvents_DocumentOpenedEventHandler(DocumentEvents_DocumentOpened);

         ... 
    }

        void DocumentEvents_DocumentOpened(Document Document)
    {
        MessageBox.Show("Not called");
    }

我也尝试过 DocumentEvents,但没有成功。有什么想法吗?

【问题讨论】:

    标签: visual-studio-addins envdte


    【解决方案1】:

    我刚刚意识到我专注于错误的事件,这就是它没有被触发的原因。通过下面的代码,我得到了我想要的。所以我不得不使用 WindowEvents 而不是 DocumentEvents。

              ....            
    
       _applicationObject.Events.WindowEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(WindowEvents_WindowActivated);
    
        }
    
        void WindowEvents_WindowActivated(Window GotFocus, Window LostFocus)
        {
            if (ucCAST != null && GotFocus.Document != null)
                ((CAST)ucCAST).refreshCode(GotFocus.Document.Name);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多