【问题标题】:Reusing the same contextMenu xml for ContextMenuMailItem and ContextMenuMultipleItems为 ContextMenuMailItem 和 ContextMenuMultipleItems 重用相同的 contextMenu xml
【发布时间】:2017-05-30 03:38:26
【问题描述】:

在 VSTO Outlook 加载项(适用于 Outlook 2009+)中将项目添加到上下文菜单(功能区)时,有没有办法为多个 idMso 使用相同的上下文菜单(即,我想添加选择单个或多个电子邮件时的相同项目)?我尝试了下面的 xml,但架构不喜欢我在多个地方重复使用相同的按钮 id。

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <contextMenus>
    <contextMenu idMso="ContextMenuMailItem">
      <button id="DoThis"
          label="Label"
          onAction="DoThis"
          getVisible="GetVisible"/>
    </contextMenu>
    <contextMenu idMso="ContextMenuMultipleItems">
      <button id="DoThis"
          label="Label"
          onAction="DoThis"
          getVisible="GetVisible"/>
    </contextMenu>
  </contextMenus>  
</customUI>

理想情况下,我想我想要这样的东西:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <contextMenus>
    <contextMenu idMso="ContextMenuMailItem,ContextMenuMultipleItems">
      <button id="DoThis"
          label="Label"
          onAction="DoThis"
          getVisible="GetVisible"/>
    </contextMenu>
  </contextMenus>  
</customUI>

【问题讨论】:

    标签: vsto outlook-addin ribbon


    【解决方案1】:

    无法重用id 属性,但还有另一个可重用的属性-tag:

    <button id="DoThis1" tag="DoThis" ... />
    <button id="DoThis2" tag="DoThis" />
    

    然后在代码中你可以通过控件的Tag属性而不是Id来确定命令。

    【讨论】:

    • 在这种情况下,您甚至不需要标签。正如你所说,id 必须不同,但你可以在两个按钮上具有相同的 onAction 属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-12
    • 2011-04-09
    • 1970-01-01
    • 2014-12-21
    • 1970-01-01
    • 2018-02-17
    相关资源
    最近更新 更多