Why RibbonGallery.buttons can't add RibbonButton RRS feed

  • Question

  • The codes:  

         private void galleryCover_ItemsLoading(object sender, RibbonControlEventArgs e)
                   Microsoft.Office.Tools.Ribbon.RibbonButton button1;
                   button1 = this.Factory.CreateRibbonButton();
                   button1.Name = "button1";
                   button.Label = "button1";


    Set for read-only. Can not change the collection content.

    galleryCover is RibbonGallery.

    Why can't add button to collection?


    Tuesday, November 6, 2012 2:47 AM


  • Hi ncs_david

    This is a slippery concept, but I hope I can explain it...

    The only Ribbon control to which Buttons can be added dynamically (at run-time) is the DynamicMenu control. Other than this, buttons must be defined at design time.

    The Gallery control is designed to allow you to dynamically change the Items. The event ItemsLoading is designed for this purpose.

    But the collection of Buttons that can be associated with a Gallery control is not an item.

    You can define the Buttons for a Gallery control in the Ribbon Designer by 1. selecting the Gallery control in the Designer; 2. Going to the Buttons item in the Properties window; 3. Clicking the ... button to the right of (Collection) in the property field; 4. In the dialog box that is displayed, click "Add" for every button you want at the bottom of the Gallery and set the properties.

    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by ncs_david Friday, November 9, 2012 3:27 AM
    Tuesday, November 6, 2012 10:39 AM