Generally, in vsto, you can use a visual editor to develop the ribbon functional area. The reference and modification property values between controls are no different from winform development, which is very convenient, however, to implement more complex functions, you have to go to the development in the XML editor, but it seems that mutual access between controls is not so direct, because the XML designer uses a large number of callback mechanisms in the fluent UI, that is to say, the attribute modification of each control must pass the callback method. On the other hand, because of the caching mechanism, ui updates must also be triggered by invalidatecontrol.
The following example shows how to modify the value of the label control by clicking the button.
<?xml version="1.0" encoding="UTF-8"?><customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load"> <ribbon> <tabs> <tab idMso="TabAddIns"> <group id="MyGroup" label="My Group"> <labelControl id="mylabel" getLabel="GetLabel"/> <button id="mybutton" label="Click Me" onAction="Click"/> </group> </tab> </tabs> </ribbon></customUI>
Add code:
private string _label = "Label";
public string GetLabel(Office.IRibbonControl control)
{
return _label;
}
public void Click(Office.IRibbonControl control)
{
_label = "Changed By Button";
ribbon.InvalidateControl("mylabel");
}
Note the following:
1. The label and getlabel of labelcontrol cannot appear at the same time in XML; otherwise, the label control cannot be seen at vsto startup.
2. All controls have at least one ID attribute. Otherwise, the control cannot be seen during vsto startup.
3. The callback function must be defined according to the proxy prototype.