none
Untoggle button when curent mail window is closed. RRS feed

  • Question

  • Hi, 

    I'm stuck with a small problem. I developed an outlook add-in which uses for ribbon a toggle button. 

    Problem I have is that if I open an email window and press the button than close the window and open another one the button will still be pressed. I'm looking for a solution where to reset the button toggle when the current window is closed.

    May be easy but haven't worked too much with this thinks and I'm a bit stucked.

    Thanks.

    Tuesday, November 6, 2018 2:40 PM

Answers

  • Hey, 

    I found a solution.

    Need a callback to invalidate the ribbon when an inspector is activated. You can add this event handler whenever a new inspector is created.

    public class MyRibbon: Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;
    
        public void Ribbon_Load(Office.IRibbonUI ribbonUI)
        {
            this.ribbon = ribbonUI;
            // ensure that any new inspectors created have a callback to refresh the button state on ativation.
            Globals.ThisAddIn.Application.Inspectors.NewInspector += Inspectors_NewInspector;
        }
    
        void Inspectors_NewInspector(Outlook.Inspector Inspector)
        {
            ((Outlook.InspectorEvents_10_Event)Inspector).Activate += Inspector_Activate;
        }
    
        void Inspector_Activate()
        {
            ribbon.Invalidate();
        }
    }

    • Marked as answer by Bogdan-Sorin Wednesday, November 7, 2018 11:52 AM
    Wednesday, November 7, 2018 11:52 AM

All replies

  • Hi Bogdan,

    Please try the code as below:

    <toggleButton id="toggleButton1"
    
    size="large"
    
    label="Show Pane"
    
    screentip="Click to show or hide the pane"
    
    onAction="OnToggleButton1"
    
    getPressed="GetPressed"  />
    
     
    
    public bool GetPressed(Office.IRibbonControl control)
    
    {
    
    return true;
    
    }

    For more information, please review the following link:

    Using toggleButton in ribbon for Outlook Addin

    Hopefully it helps you.

    Best Regards,

    Yuki


    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.

    Wednesday, November 7, 2018 3:02 AM
    Moderator
  • Hey Yuki,

    Thanks for reply. This does not solve my problem. What I want to achieve is to reset the press state of the button whenever I close the current mail window(e.g. new mail, reply, etc...). 

    Wednesday, November 7, 2018 6:51 AM
  • Hey, 

    I found a solution.

    Need a callback to invalidate the ribbon when an inspector is activated. You can add this event handler whenever a new inspector is created.

    public class MyRibbon: Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;
    
        public void Ribbon_Load(Office.IRibbonUI ribbonUI)
        {
            this.ribbon = ribbonUI;
            // ensure that any new inspectors created have a callback to refresh the button state on ativation.
            Globals.ThisAddIn.Application.Inspectors.NewInspector += Inspectors_NewInspector;
        }
    
        void Inspectors_NewInspector(Outlook.Inspector Inspector)
        {
            ((Outlook.InspectorEvents_10_Event)Inspector).Activate += Inspector_Activate;
        }
    
        void Inspector_Activate()
        {
            ribbon.Invalidate();
        }
    }

    • Marked as answer by Bogdan-Sorin Wednesday, November 7, 2018 11:52 AM
    Wednesday, November 7, 2018 11:52 AM