我有一个以下类型的Outlook功能区: Microsoft.Outlook.Mail.Compose,Microsoft.Outlook.Mail.Read
我需要根据邮件项目的内容(正文)启用或禁用此功能区中的按钮,我想在功能区的Load事件上执行此操作。
我有以下代码,但ActiveInspector始终为null。
private void RiverRaftRibbon_Load(object sender, RibbonUIEventArgs e)
{
var application = Globals.ThisAddIn.Application;
var inspector = application.ActiveInspector();
MailItem myMailItem = (MailItem)inspector.CurrentItem;
string projectName;
DateTime? dueDate;
if (Common.ParserHelper.IsRiverRaftEmail(mail.HTMLBody, out projectName, out dueDate))
{
btnAccept.Enabled = true;
}
else
btnAccept.Enabled = false;
}
谢谢!
答案 0 :(得分:4)
试试这个:
var application = Globals.ThisAddIn.Application;
Outlook.Selection selection = application.ActiveExplorer().Selection;
mailItem = selection[1] as Outlook.MailItem;