Search code examples
c#vstoribbontogglebutton

How to detect the state of a toggle button on a ribbon?


I've added a toggle button to my ribbon and now, I'd like to send its state to an other object. The code is below.

public void Butt_Click(Office.IRibbonControl control)
{
  something.SendButtVal(control.State);
}

Of course, control.State doesn't work. I suspect that I'll need to cast control to type ToggleButton or something like that but intellisense gives me nothing...

I can see that the API for the interface IRibbonControl is here but I'd like to see a list of implementing classes, like in JavaDocs. How do I get there?

EDIT

Please note that I'm asking about a ribbon component. See the method signature. It's a toggle button on a ribbon. The problem is that I don't get Checked property and (probably) need to cast control to correct type.


Solution

  • You need to alter your signature. It's not correct for a toggle button. See here for details.

    public void ToggleButtonOnAction(IRibbonControl control, bool pressed)
    {
      MessageBox.Show("ToggleButton was switched " + pressed ? "on" : "off");
    }