VSTO Outlook 加载项:无法使用资源管理器关闭事件

VSTO Outlook AddIn: Cannot use Explorer Close event

前段时间我使用 NetOffice 编写了一个 Outlook AddIn,效果很好。现在有了新的 Visual Studio Community 2017,我可以在没有 NetOffice 帮助的情况下编写 Office AddIns。所以我想更改我的代码,但我 运行 遇到了一个问题:我无法订阅 Explorer.Close 事件:

using Outlook = Microsoft.Office.Interop.Outlook;
namespace OLTest2
{
    public class ExplorerHandle
    {
        private Outlook.Explorer OutlookExplorer;
        public void InitExplorer(Outlook.Explorer expl)
        {
            OutlookExplorer = expl;
            // The next two lines compile:
            OutlookExplorer.BeforeItemPaste += BeforeItemPasteEvent;
            OutlookExplorer.SelectionChange += SelectionChangeEvent;

            // ***Next line does not compile***:
            OutlookExplorer.Close += CloseEvent; // "Cannot assign to 'Close' because it is a 'method group'"
            
            // This is the old NetOffice code which worked fine:
            /* 
            OutlookExplorer.BeforeItemPasteEvent += BeforeItemPasteEvent;
            OutlookExplorer.SelectionChangeEvent += SelectionChangeEvent;
            OutlookExplorer.CloseEvent += CloseEvent; 
            */ 
        }
    }
}

IntelliSense 没有向我显示 Outlook.Explorer 对象的 Close 事件的存在。但是微软告诉我应该存在这样的事件:

Explorer events on MSDN

然而,Visual Studio 告诉我只有一个 Close() 方法。

我错过了什么,但是什么?

您需要将上面的 OutlookExplorer 变量转换为 ExplorerEvents 接口。

感谢 Dmitry,他为我指明了正确的方向。 Close 事件的解决方案是: ((Outlook.ExplorerEvents_10_Event)OutlookExplorer).Close += CloseEvent;

如果有人遇到与 OutlookInspector 类似的问题: 演员是必要的,例如Activate 事件: ((Outlook.InspectorEvents_10_Event)OutlookInspector).Activate += ActivateEvent;

但我很好奇:为什么我必须转换才能订阅 Close,而不是 BeforeItemPaste? 根据我在原始问题中发布的 link,这两个事件都是 "Inherited from ExplorerEvents_10_Event"。