在尝试开发我的第一个 VS Addin 时,我在触发 DTE2 事件时遇到了问题。
基本上, DocumentOpened 和 LineChanged 事件由于某种原因不会触发。我错过了什么重要的部分?
namespace TestAddin {
public class Connect : IDTExtensibility2 {
private AddIn _addInInstance;
private DTE2 _applicationObject;
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) {
_applicationObject = (DTE2) application;
_addInInstance = (AddIn) addInInst;
_applicationObject.Events.DocumentEvents.DocumentOpened += InitializeFoldingOnDocument;
_applicationObject.Events.TextEditorEvents.LineChanged += UpdateFoldingOnDocument;
}
private void UpdateFoldingOnDocument(TextPoint startpoint, TextPoint endpoint, int hint) {
RegionFolding(_applicationObject.ActiveDocument);
}
private void InitializeFoldingOnDocument(Document document) {
RegionFolding(document);
}
private void RegionFolding(Document _document) {
// Do the folding [...]
}
// Other IDTExtensibility2 Members [...]
}
}