Microsoft Office VSTO addin: How to access ribbon xml controls from ThisAddIn class

梦想与她 提交于 2020-04-29 03:49:28

问题


In my VS2019 VSTO project for WORD AddIn, I have created button in a tab by using Ribbon XML as follows. And VS2019 auto-generated the ThisAddIn.cs class shown below. Question: How can I programmatically access the button control btnButton of Ribbon XML from ThisAddIn.cs class?

Remark: There are some officials such as this one that shows how to do it for a Ribbon Designer. But, I need to do it for Ribbon XML.

Ribbon1.XML:

<ribbon>
    <tabs>
      <tab id="TabID"  label="TEST">
        <group id="MyGroup" label="My Group">
          <button id="btnButton" label="Insert Text" screentip="Test button" onAction="OnTextButton" getEnabled="Get_Enabled" tag="textButtonTag"/>
        </group>
      </tab>
    </tabs>
</ribbon>

ThisAddIn.cs:

public partial class ThisAddIn
{
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {

    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {

    }

    protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    {
        return new Ribbon1();
    }

    #region VSTO generated code

    private void InternalStartup()
    {
        this.Startup += new System.EventHandler(ThisAddIn_Startup);
        this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
    }

    #endregion
}

来源:https://stackoverflow.com/questions/61149776/microsoft-office-vsto-addin-how-to-access-ribbon-xml-controls-from-thisaddin-cl

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