Ribbon Callbacks - Office.IRibbonControl.Context is null when defining <contextMenus> RRS feed

  • Question

  • I must be missing something very simple as I've followed every example I could find and can't seem to make this work. 

    Simply put, I've created an XML file that contains <ribbon> and <contextMenus> entries. The onAction of each entry calls the proper methods, so no problem there. However, only the <ribbon> entries onAction pass the Office.IRibbonControl.Context correctly to the method as either Outlook.Inspector or Outlook.Explorer. All the <contextMenus> onAction appear to pass a null value instead. What am I missing? Perhaps I need to configure something further in my code to enable the use of <contextMenus>?

    Please point me to some examples of callbacks for <contextMenus> as they appear to work differently from <ribbon> entries. 

    thank you. 

    Thursday, May 24, 2018 3:38 PM


All replies

  • Hello Darren Shane,

    What's your Callback code? How do you design the XML? What type control the IRibbonControl is?

    I tried to create a button control and get the Context in callback function. It is not null. What's your situation?

    Here is the code I'm using.

        <contextMenu idMso="ContextMenuMailItem">
          <button id="btnInContextMenu" label ="TestButton" onAction ="MyCustomCallback"/>    

    public void MyCustomCallback(Office.IRibbonControl ribbonControl)
                var a = ribbonControl.Context;
                if (a == null) {
                    MessageBox.Show("RibbonControl Context is null");

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, May 25, 2018 5:15 AM
  • Hi Terry, thank you for replying.

    My code is similar to yours in structure except I'm using <contextMenu idMso="ContextMenuContactItem">. That said, I've done a quick check on ribbonControl.Context being null and you are correct it is not. What lead me to believe it was being passed a null was my code crashing with a null on this statement:

    var item = control.Context as Outlook.Explorer;
    Object selObject = item.Application.ActiveExplorer().Selection[1];

    Of course I've wrapped some protection around it since to prevent the crash looking for the context to be Explorer first. Which brings me to the next question... I expanded your code (see below) and the context is not null, Explorer, or Inspector. When the callback is run from <tab idMso="TabContacts"> the context is Explorer and it works correctly. What should I expect when a callback is from <contextMenu idMso="ContextMenuContactItem"> and if I'm to expect something completely different, please point me to some examples to handle that case. Thank you. 

    var a = control.Context;
    System.Windows.Forms.MessageBox.Show("Ready RibbonControl Context");
    if (a == null)
      System.Windows.Forms.MessageBox.Show("RibbonControl Context is null");
    if (a is Outlook.Explorer)
      System.Windows.Forms.MessageBox.Show("RibbonControl Context is Explorer");
    if (a is Outlook.Inspector)
      System.Windows.Forms.MessageBox.Show("RibbonControl Context is Inspector");

    Friday, May 25, 2018 1:16 PM
  • With a little help from a VBA assembly and the below statement, I was able to figure out the context  being passed is Outlook.Selection I was able to get everything working. 


    • Marked as answer by Darren Shane Friday, May 25, 2018 10:32 PM
    Friday, May 25, 2018 2:52 PM
  • Extending the User Interface in Outlook 2010 identifies the objects returned by IRibbonControl.Context for the various context menus

    • Marked as answer by Darren Shane Friday, May 25, 2018 10:32 PM
    Friday, May 25, 2018 8:54 PM