visual-studio-addins - Visual Studio 2010 插件 - 未触发事件

标签 visual-studio-addins envdte

我编写了一个将事件文档作为参数的插件。所以每次事件文档发生变化时,我都需要知道。为此,我想使用 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/

相关文章:

c# - VS 扩展 : TextPoint. 大于/小于大文件非常慢

c# - 在 Visual Studio 2010 语言服务中实现查找引用

visual-studio - 如何在我的方法名称单词之间自动插入下划线?

qt - 如何在Visual C++ 2010中导入QT项目?

vsx - VS 2010扩展性: Create a extension to automatically wrap selected text (code) in comments and adding a comment above it

c# - Visual Studio 扩展 : Change the hint path of an assembly reference

c# - 如何提供 ProjectItem.get_FileNames(i) 的实现?

c# - 无法将 DTE、项目或解决方案转换为 VCProject 和 VCCodeModel