Change Ribbon-menu properties after ribbon-load

扶醉桌前 提交于 2019-12-25 19:47:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!