I've created an Outlook Add-In, and I'm using an XML ribbon configuration file to specify a new tab, and button. The button loads into a new tab within outlook. Now sometimes, based on user we want to be able to hide or disable these buttons. What's the simplest way to disable a menu button on a custom tab through the Outlook Interop api?
My first guess is that I need to iterate through some command bar collections after my ribbon is created, and then search for my menu buttons, but I'm not sure where these collections are.
protected override Microsoft.Office.Core.IRib开发者_JAVA百科bonExtensibility CreateRibbonExtensibilityObject()
{
this.ribbon = new MyRibbon();
// loop through tabs and ribbon items, look for my custom control, and enabled/disable specific buttons.
return this.ribbon;
}
Sorry to answer my own question. Finally figured it out. Within the xml configuration there is a getVisible callback for buttons/groups/tabs.
So all you need to do is add the callback in the xml, in my case I did it for a group:
<ribbon>
<tabs>
<tab idQ="myNs:myTab" label="My Label" >
<group id="settingsGroup" label="Settings" getVisible="Control_Visible" >
<button id="preferences" label="Preferences" image="configuration.png"
screentip="Preferences" size="large" onAction="Settings_Click" supertip="Preferences" />
</group>
</tab>
</tabs>
</ribbon>
and create a callback method
public bool Control_Visible(Office.IRibbonControl control)
{
// In order to maintain a reference to the groups, I store the controls into a List<Office.IRibbonControl>.
if(!this.groupControls.Contains(control))
{
this.groupControls.Add(control);
}
// logic here to determine if it should return true or false to be visible...
return true;
}
Then if during the use of outlook, you change the visibility setting of a button/tab/group, you need to call Invalidate() method on the ribbon so the ribbon redraws. IE:
this.ribbon.Invalidate();
精彩评论