Search code examples
c#office-addinsribbonexcel-addinsexcel-iribbonui

UI Ribbon: How to unpress a toggle button?


enter image description here

There are 4 toggle buttons, when I be click on one, the other 3 are not clicked For example, when I click public, Confidential's Click will be removed. Only 1 can be selected.

 <toggleButton id="textButtonpublic" getLabel="getpublic" getImage="getcolor" onAction="PublicAction" getVisible="getvisiblepublic"  getPressed="GetPressedPublic"   />

public void PublicAction(IRibbonControl control, bool pressed){
GetPressedConfidential();}


 public bool GetPressedConfidential(IRibbonControl control)
    {
        return false;
    }

It didn't work when I called the GetPressedConfidential method.


Solution

  • If the ribbon button comes from your add-in you need to use the Invalidate or InvalidateControl methods of the IRibbonUI interface that allows invalidating the cached value for a single control or all controls on the Ribbon user interface.

    For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in place for the control until the add-in signals that the cached values are invalid by using the InvalidateControl method, at which time, the callback procedure is again called and the return response is cached.

    The getPressed callback has the following signature for the toggelButton control:

    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
    

    The Fluent UI (aka Ribbon UI) is described in depth in the following articles: