开发者

Visual Studio 2010 add in - events not triggered

I have written an add in that takes the active document as a parameter. So each time that the active document has changed, I need to know. To do so, I wanted to use "Events.DocumentEvents.DocumentOpened" event of the DTE2 object. But the problem is that event is never get fired even though I change the active document.

The code snippet is as follows

        pu开发者_Go百科blic 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");
    }

I have tried with DocumentEvents as well but no success. Any ideas?


I had just realized that I focused on the wrong event and thats why it was not fired. With the code below I got what I intended to. So instead of DocumentEvents, I had to use WindowEvents.

          ....            

   _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);
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜