4

i am developing vsto and i would like to hide some controls on the ribbon Particulary i need to hide menu - Change Styles on styles group in home tab. I tried to do it via xml:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab idMso="TabHome">
        <group idMso="GroupStyles">
          <menu idMso="ChangeStylesMenu" visible="0"/>
        </group>
      </tab>

    </tabs>
  </ribbon>
</customUI>

but menu is still visible it looks like i cant get this control. My question is anyone can get this control? Via xml or via code? By the way what is the way to get ribboncontrols programmatically. I know that there is RibbonGroup class but i dont know how to load it(how to get it via id) If i could do it i would get all items belongs to it. Any ideas?

Kara
  • 6,115
  • 16
  • 50
  • 57

1 Answers1

4

Here is one way to do so in C#:

// disable all controls in ribbon
foreach (RibbonGroup group in Globals.Ribbons.MyRibbon.MyTab.Groups)
{
    foreach (RibbonControl control in group.Items)
    {
        control.Enabled = false;
    }
}

Notice that MyTab is the name (controlID) of the tab in your ribbon.

etaiso
  • 2,736
  • 3
  • 26
  • 38
  • I have two guesses on the answer above: 1) For some RibbonControls you have to do more/other than set "Enabled = false". E.g. for a SplitButton you have to set "splitButton.ButtonEnabled = false" 2) The Disable-Function should be recursive because you can have child controls e.g. in a RibbonMenu-Control – jreichert Jan 13 '15 at 14:05