我编写了一个将事件文档作为参数的插件。所以每次事件文档发生变化时,我都需要知道。为此,我想使用 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,但没有成功。有任何想法吗?
最佳答案
我刚刚意识到我关注了错误的事件,这就是它没有被解雇的原因。通过下面的代码,我得到了我想要的。因此,我不得不使用 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);
}
关于visual-studio-addins - Visual Studio 2010 插件 - 未触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5157309/