问题
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";
}
回答1:
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);
来源:https://stackoverflow.com/questions/53257273/change-ribbon-menu-properties-after-ribbon-load