-1

I build a VSTO (made with the Ribbon Designer, not using Ribbon XML). Is it possible to change the properties (like label) of the Tab from Ribbon1.cs ?

I even can't change the ribbon title with :

    private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
    {
        myRibbon.Label = "something";
    }
T.Todua
  • 53,146
  • 19
  • 236
  • 237
  • It's not clear what you're asking. Do you mean the `Tab` label? A Ribbon does not have a `Label` property and it's not clear what you'd be trying to change with that. Also, the code you show us is changing a property when the Ribbon loads, but the title of the question says "after ribbon-load". Which do you mean? Please be as accurate and detailed as possible. – Cindy Meister Nov 12 '18 at 14:30
  • @CindyMeister sorry, yes, I mean Tab label – T.Todua Nov 12 '18 at 17:29

1 Answers1

0

The way to do this dynamically is using a callback.

In your ribbon XML:

<tab id="myTabID" getLabel="myCallback">
  ....
</tab>

In your ribbon code:

public string myCallback(IRibbonControl control)
{
    switch (control.Id)
    {
        case "myTabID":
            return "My Label";
        case "whatever else":
        default:
            return "n/a";
    }
}

The callback will execute whenever the tab is displayed, so probably on startup. When you actually want to change what's showing, you have to invalidate it:

ribbon.Invalidate();
// or
ribbon.InvalidateControl(id);
Chris
  • 3,400
  • 1
  • 27
  • 41