7

EDIT: The posters answer is correct except for it should read xmlns="http://schemas.microsoft.com/office/2009/07/customui" for the include. As a side effect the ribbon and context menu defined in an XML file will not work in Office 2007. If you need to add a context menu in 2007, use the now deprecated, and a context menu within the Outlook 2007 message window is NOT POSSIBLE.

this.Application.ItemContextMenuDisplay += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(Application_ItemContextMenuDisplay);

I've created both a Ribbon and a Context menu, but I do not know how to deploy both of them at the same time.

My Ribbon XML looks something like this:

<?xml version="1.0" encoding="UTF-8"?>

<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui">

<ribbon>

<tabs>

  <tab id="testTab" label="Test Label">

    <group id="testGroup" label="test">

      <button id="testButton" onAction="testAction" label="Test" size="large" 

          getImage ="GetCustomImage" screentip="Test Ribbon Functionality."/>         

    </group>      

  </tab>

 </tabs>

</ribbon>

</customUI>

Ribbon.cs has

public string GetCustomUI(string ribbonID)

{

  String ui = null;

  // Examine the ribbonID to see if the current item

  // is a Mail inspector.

  if (ribbonID == "Microsoft.Outlook.Mail.Read" ||

    ribbonID == "Microsoft.Outlook.Mail.Compose")

  {

    // Retrieve the customized Ribbon XML.

    ui = GetResourceText("WDCrypt2.Ribbon.xml") ;



  }

  return ui;

}

ContextMenu XML looks like (from a tutorial)

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

 <contextMenus>

  <contextMenu idMso="ContextMenuText">

   <button idMso="FontDialog" visible="false" />

   <toggleButton id="MyToggle" label="My Toggle Button" />

   <button id="MyButton" label="My Button" insertBeforeMso="HyperlinkInsert" onAction="GetButtonID" />

   <menuSeparator id="MySeparator" />

   <menu id="MySubMenu" label="My Submenu" >

    <button id="MyButton2" label="Button on submenu" />

   </menu>

   <gallery id="galleryOne" label="My Gallery">

    <item id="item1" imageMso="HappyFace" />

    <item id="item2" imageMso="HappyFace" />

    <item id="item3" imageMso="HappyFace" />

    <item id="item4" imageMso="HappyFace" />

   </gallery>

   <dynamicMenu id="MyDynamicMenu" label= "My Dynamic Menu" getContent="GetMyContent" />

  </contextMenu>

 </contextMenus>

</customUI>

With its cs file which looks like:

private Office.IRibbonUI ribbon;

public Ribbon2()
{
}

#region IRibbonExtensibility Members

public string GetCustomUI(string ribbonID)
{
  return GetResourceText("WDCrypt2.Ribbon2.xml");
}

The problem is to use either in my Addin Class I must:

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{

  return new Ribbon();

}

OR

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{

  return new Ribbon2(); //The Context Menu

}

But I cannot do both. How do I get both the context menu and the ribbon at the same time?

Edit: I would also like to refrain from using Application.ItemContextMenuDisplay, as this is officially deprecated by the API.

Shane Chin
  • 578
  • 2
  • 9
  • 20
  • Did you succeed in showing context menu in both reading and compose windows? I can only seem to show it in compose. – wpfwannabe Mar 29 '12 at 13:43
  • should it work in reading? wouldn't you just use a standard context menu off of the explorer window for preview pane? The read mode inspector is not editable. Or perhaps you have another non-mail scenario to enable in this mode. – Anonymous Type Jun 12 '13 at 23:35
  • If you are interested please commit for this :http://stackoverflow.com/documentation/outlook-addin/commit – Kushan Randima Jul 28 '16 at 04:34

1 Answers1

14

You need to combine the two ribbon XML files, then have a single callback file:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
  <tab id="testTab" label="Test Label">
    <group id="testGroup" label="test">
      <button id="testButton" onAction="testAction" label="Test" size="large" 
          getImage ="GetCustomImage" screentip="Test Ribbon Functionality."/>         
    </group>      
  </tab>
 </tabs>
</ribbon>
<contextMenus>
  <contextMenu idMso="ContextMenuText">
   <button idMso="FontDialog" visible="false" />
   <toggleButton id="MyToggle" label="My Toggle Button" />
   <button id="MyButton" label="My Button" insertBeforeMso="HyperlinkInsert" onAction="GetButtonID" />
   <menuSeparator id="MySeparator" />
   <menu id="MySubMenu" label="My Submenu" >
    <button id="MyButton2" label="Button on submenu" />
   </menu>
   <gallery id="galleryOne" label="My Gallery">
    <item id="item1" imageMso="HappyFace" />
    <item id="item2" imageMso="HappyFace" />
    <item id="item3" imageMso="HappyFace" />
    <item id="item4" imageMso="HappyFace" />
   </gallery>
   <dynamicMenu id="MyDynamicMenu" label= "My Dynamic Menu" getContent="GetMyContent" />
  </contextMenu>
 </contextMenus>
</customUI>
John Nilsson
  • 17,001
  • 8
  • 32
  • 42
Jake Ginnivan
  • 2,112
  • 16
  • 20
  • 1
    this is correct, but the real heart of the issue was that you cannot define the context menu and the ribbon load with that header, as the ribbon context menu is too new for that one, I will edit your post accordingly. EDIT : actually I can't so if you could change your xmlns to "http://schemas.microsoft.com/office/2009/07/customui", your answer will be correct. – Shane Chin Jul 15 '11 at 19:05