我正在尝试在Outlook中的上下文菜单项中添加按钮。我确实覆盖了CreateRibbonExtensibilityObject()
中的ThisAddin.cs
并创建了如下的自定义 ContextMenuItem 。
ThisAddin.cs
protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new OutlookAddInExtensibility();
}
OutlookAddInExtensibility 类可实现自定义功能区上下文菜单项。
[ComVisible(true)]
internal class OutlookAddInExtensibility : IRibbonExtensibility
{
public string GetCustomUI(string RibbonID)
{
return
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<customUI xmlns=""http://schemas.microsoft.com/office/2009/07/customui"">
<contextMenus>
<contextMenu idMso=""ContextMenuMailItem"">
<button
id=""MyContextMenuMailItem""
label=""ContextMenuMailItem""
onAction=""RibbonMenuClick""
getVisible=""GetVisible""/>
/>
</contextMenu>
</contextMenus>
</customUI>
";
}
public bool GetVisible(Microsoft.Office.Core.IRibbonControl control)
{
return true;
}
public void RibbonMenuClick(IRibbonControl control)
{
var selection = control.Context as Microsoft.Office.Interop.Outlook.Selection;
var mailItems = selection.OfType<Microsoft.Office.Interop.Outlook.MailItem>().ToList();
System.Diagnostics.Trace.WriteLine($"RibbonMenuClick control: {control} type {control?.GetType().Name ?? "(null)"}");
}
}
它也删除了我现有的 Addin 图标。当我执行此操作时,右键单击 MailItem 时没有显示上下文菜单项。
第一次使用 Outlook插件时,在此方面苦苦挣扎,但却不明白我在做什么错?