首页 > 解决方案 > Globals.ThisAddIn.Application.ActiveInspector == null 虽然显示了有效的 Outlook.AppointmentItem 为什么?

问题描述

我正在使用 VSTO 开发一个 Outlook 插件。

在方法中:this.Load += new Microsoft.Office.Tools.Ribbon.RibbonUIEventHandler(this.MyApp_Load);

在我的功能区的 MyApp_Load 中,我使用以下代码:

if (Globals.ThisAddIn.isLoggedIn())
{
    btnMyApp.Visible= true;
    Outlook.Inspector inspector = 
         Globals.ThisAddIn.Application.ActiveInspector();
    if (inspector != null && inspector.CurrentItem != null)
    {

当我在 Outlook 中打开 AppointmentItem 时,我可以调试上面的代码。不幸的是 ActiveInspector() == null 尽管正在显示有效的 AppointmentItem。

为什么?

标签: vstooutlook-addin

解决方案


在显示检查器之前调用该方法。您必须使用RibbonUI传递作为onLoad回调的参数并RibbonUI.Context转换为Inspector接口。


推荐阅读