Visual Studio 2010 add in - events do not fire

I wrote an addendum that takes the active document as a parameter. Therefore, every time an active document changes, I need to know. For this, I wanted to use the event "Events.DocumentEvents.DocumentOpened" of the DTE2 object. But the problem is that the event never fires, although I am changing the active document.

Below is a snippet of code

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"); } 

I also tried with DocumentEvents, but did not succeed. Any ideas?

+4
source share
1 answer

I just realized that I was focusing on the wrong event, and therefore he was not fired. With the code below, I got what I wanted. 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); } 
+3
source

Source: https://habr.com/ru/post/1341849/


All Articles