'VSTO ribbon xml set callback attribute in 'template' for each control type
I have a C# VSTO Excel add-in that uses XML for the ribbon. In it, there are multiple ToggleButtons that all use the same functions used in their 'getLabel', 'getKeytip', 'getScreentip', 'getSupertip', 'getPressed', & 'onAction' callbacks. Those functions then return the correct value or execute the correct code based on the control's ID.
Is it possible to create a 'template' for these elements that sets these attributes, but allows me to provide the ID?
For example here is what I currently have:
<toggleButton
id="tb1"
getLabel="GetLabel"
getKeytip="GetKeytip"
getScreentip="GetScreentip"
getSupertip="GetSupertip"
getPressed="Togglebutton_GetPressed"
onAction="Togglebutton_OnAction"/>
<toggleButton
id="tb2"
getLabel="GetLabel"
getKeytip="GetKeytip"
getScreentip="GetScreentip"
getSupertip="GetSupertip"
getPressed="Togglebutton_GetPressed"
onAction="Togglebutton_OnAction"/>
<toggleButton
id="tb3"
getLabel="GetLabel"
getKeytip="GetKeytip"
getScreentip="GetScreentip"
getSupertip="GetSupertip"
getPressed="Togglebutton_GetPressed"
onAction="Togglebutton_OnAction"/>
<toggleButton
id="tb4"
getLabel="GetLabel"
getKeytip="GetKeytip"
getScreentip="GetScreentip"
getSupertip="GetSupertip"
getPressed="Togglebutton_GetPressed"
onAction="Togglebutton_OnAction"/>
<toggleButton
id="tb5"
getLabel="GetLabel"
getKeytip="GetKeytip"
getScreentip="GetScreentip"
getSupertip="GetSupertip"
getPressed="Togglebutton_GetPressed"
onAction="Togglebutton_OnAction"/>
And I'd like to be able to specify a 'template':
<toggleButtonTemplate
getLabel="GetLabel"
getKeytip="GetKeytip"
getScreentip="GetScreentip"
getSupertip="GetSupertip"
getPressed="Togglebutton_GetPressed"
onAction="Togglebutton_OnAction"/>
And then have my ribbon XML be updated to something like:
<toggleButtonTemplate
id="tb1"/>
<toggleButtonTemplate
id="tb2"/>
<toggleButtonTemplate
id="tb3"/>
<toggleButtonTemplate
id="tb4"/>
<toggleButtonTemplate
id="tb5"/>
Is something like this possible? If so, how would I go about doing it?
Solution 1:[1]
Yes, it is possible. Use .net BCL for dealing with XML files. You can generate the ribbon XML at runtime and add attributes to the XML files dynamically using the XmlDocument class from the System.XML namespace. See Adding attributes to an XML node for more information.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eugene Astafiev |
