问题
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