4

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

代码片段如下

        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 但没有成功。有任何想法吗?

4

1 回答 1

3

我刚刚意识到我专注于错误的事件,这就是它没有被解雇的原因。通过下面的代码,我得到了我想要的。所以我不得不使用 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);
    }
于 2011-03-03T13:34:26.007 回答