【问题标题】:How to have more than one context menu in a custom office Ribbon如何在自定义办公室功能区中拥有多个上下文菜单
【发布时间】:2017-09-18 07:25:30
【问题描述】:

我正在尝试为 Powerpoint 的 Office 插件添加两个上下文菜单。第一个出现在用户右键单击幻灯片时,第二个出现在用户右键单击选定的形状时。它们分开工作,这里是 Ribbon xml:

<contextMenus>
<contextMenu idMso="ContextMenuShape">
    <button id=".../>
</contextMenu>
</contextMenus>

和:

<contextMenus>
<contextMenu idMso="ContextMenuFrame">
    <button id=.../>
</contextMenu>
<contextMenus>

但是当我尝试同时拥有两者时,要么通过将两个 contextMenu 元素嵌套在 contextMenus 元素中,要么让两个单独的 contextMenus 元素都不显示。有没有办法做到这一点,或者我必须只有一个 contextMenu?

【问题讨论】:

    标签: vba powerpoint contextmenu office-addins ribbon


    【解决方案1】:

    &lt;contextMenus&gt; 元素是&lt;contextMenu&gt; 项目的容器。在您的ribbon.xml 中,您需要将所有上下文菜单项放入“contectMenus”容器中。例如:

    <contextMenus>
      <contextMenu idMso="ContextMenuShape">
        <button id="id_shape" label="Label 1"/>
      </contextMenu>
      <contextMenu idMso="ContextMenuFrame">
        <button id="id_ffame" label="Label 2"/>
      </contextMenu>
    </contextMenus>
    

    要自定义上下文项的可见性,您需要使用每个上下文菜单内元素的“GetVisible”和“GetEnabled”处理程序;在示例中,这些是按钮。

    【讨论】:

    • 谢谢@Slava,这很好用。以前它对我不起作用的原因是我有重复的 id 并且没有验证我的 xml
    猜你喜欢
    • 2013-08-24
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多