Outlook VSTO 添加上下文菜单项 [英] Outlook VSTO add context menu item

查看:37
本文介绍了Outlook VSTO 添加上下文菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向附件上下文菜单中添加一个菜单项.问题是该项目不显示.我看过一些例子,他们说这段代码应该可以工作:

I am trying to add a menu item to the attachment context menu. The problem is that the item does not show up. I've seen some examples where they say that this code should work:

this.Application.AttachmentContextMenuDisplay += new ApplicationEvents_11_AttachmentContextMenuDisplayEventHandler(ThisAddIn_AttachmentContextMenuDisplay);

private void ThisAddIn_AttachmentContextMenuDisplay(CommandBar commandBar, AttachmentSelection attachments)
{
    if (attachments.Count > 0)
    {
        var cbc = commandBar.Controls.Add(
                  MsoControlType.msoControlButton,
                  missing, missing, missing, true);

        cbc.Caption = "My custom item";
    }
}

事件 ThisAddIn_AttachmentContextMenuDisplay 被触发,附件计数大于零,但不显示菜单项.

The event ThisAddIn_AttachmentContextMenuDisplay is fired and the attachment count is larger than zero, but the menu item is not displayed.

奇怪的是,如果我调用 commandBar.ShowPopup(); 然后菜单项将显示(注意缺少的图标),但是当它被点击时,上下文菜单将再次显示:

Strange thing is that if I call commandBar.ShowPopup(); then the menu item will show (note the missing icons), but when it is clicked the context menu will show a second time:

不调用commandBar.ShowPopup();上下文菜单看起来像往常一样,但缺少我的自定义项:

Without calling commandBar.ShowPopup(); the context menu looks as usual, but it is missing my custom item:

我使用的是 Visual Studio 2013 和 Outlook 2010

I am using Visual Studio 2013 and Outlook 2010

推荐答案

命令栏已弃用,不应再使用,除非以编程方式运行控件(请参阅 ExecuteMso).您需要改用功能区 UI(又名 Fluent UI).请参阅 在 Outlook 2010 中扩展用户界面 了解更多信息.

Command bars were deprecated and shouldn't be used any longer except running controls programmatically (see ExecuteMso). You need to use the Ribbon UI (aka Fluent UI) instead. See Extending the User Interface in Outlook 2010 for more information.

在以下系列文章中阅读有关 Fluent UI 的更多信息:

Read more about the Fluent UI in the following series of articles:

如果您需要根据上下文隐藏或显示某些控件,您可以处理功能区回调,您可以在其中决定是否应向用户显示控件.

If you need to hide or show some controls depending on the context you can handle ribbon callbacks where you can decide whether a control should be shown to a user or not.

这篇关于Outlook VSTO 添加上下文菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆