1
votes

When adding items to a context menu (ribbon) in a VSTO outlook add-in (for Outlook 2009+), is there a way to use the same context menu for multiple idMso (i.e., I'd like to add the same items for when single or multiple emails are selected)? I tried the xml below, but the schema doesn't like that I'm re-using the same button id in multiple places.

<?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>

Ideally I guess I'd like something like this:

<?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>
1

1 Answers

1
votes

Reusing id attribute is not possible, but there is another attribute that is reusable - tag:

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

Then in the code then you can determine the command not by Id but by Tag property of the control.