Search code examples
c#outlookvstooutlook-addinribbonx

How Can I save Ribbon Settings made in the Outlook Explorer Window and also display und use them in the Outlook MailItem Window?


For my Outlook Add-In I created a Ribbon with XML and several OnAction Methods. My Ribbon has Toggle Buttons which enalbe several functions when being activated. My Problem is that If the User clicks the Button in the Ribbon of the Explorer Window of Outlook and after that creates a new Mail (opens the MailItem Window) the settings which have been made in the Ribbon of the Explorer Window are not transferred to the Ribbon of the MailItem Window.

This is the Ribbon of the Explorer Window: Ribbon Explorer

This is the Ribbon of the MailItem Window: Ribbon MailItem


Solution

  • You need to specify the getPressed callback for the toggleButton control on the ribbon. It enables you to specify whether the toggle button control is pressed. The callback has the following signature:

    C#: bool GetPressed(IRibbonControl control)
    
    VBA: Sub GetPressed(control As IRibbonControl, ByRef returnValue)
    
    C++: HRESULT GetPressed([in] IRibbonControl *pControl, [out, retval] VARIANT_BOOL *pvarfPressed)
    
    Visual Basic: Function GetPressed(control As IRibbonControl) As Boolean
    

    So, when somebody clicks the button on the explorer window you can save the state using a boolean variable (it is up to you how to maintain the state) and in the getPressed callback you can return the cached value.

    Read more about the Fluent UI (aka Ribbon UI) in the following series of articles: