none
Using VSTO, getItemImage not working for Ribbon gallery items. RRS feed

  • Question

  • In my VSTO 2010 application level custom Add-in for Word 2007, the getItemImage callback is NOT working for gallery control. HOWEVER, the getImage callback DOES work. The complete code is as follows. Please help: Thanks..Nam

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
           <group id="group1" label="Group 1">
              <gallery id="TestGallery" columns="1" rows="1" label="Test Gallery" getItemHeight="GetItemHeight" getItemWidth="GetItemWidth" getItemImage="GetItemImage" getShowImage="GetShowImage">
                <item id="item1" />
              </gallery>
            </group>
            <group id="group2" label="Group 2">
              <button id="button1" getImage="GetImage"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    The callbacks are as follows:

    public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                this.ribbon = ribbonUI;
            }
            internal class PictureConverter : AxHost
            {
                private PictureConverter() : base(String.Empty) { }
                static public stdole.IPictureDisp ImageToPictureDisp(Image image)
                {
                    return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);
                }
                static public stdole.IPictureDisp BitmapToPictureDisp(Bitmap oBitmap)
                {
                    return ImageToPictureDisp(oBitmap);
                }
                static public Image PictureDispToImage(stdole.IPictureDisp picture)
                {
                    return GetPictureFromIPicture(picture);
                }
            }
            public stdole.IPictureDisp GetImage(IRibbonControl oRbnCtrl)
            {
                return PictureConverter.BitmapToPictureDisp(Properties.Resources.image001);
            }
            public stdole.IPictureDisp GetItemImage(IRibbonControl oRbnCtrl, int iItemIndex)
            {
                switch (iItemIndex)
                {
                    case 0:
                        return PictureConverter.BitmapToPictureDisp(Properties.Resources.image002);
                }
                return PictureConverter.BitmapToPictureDisp(Properties.Resources.image002); ;
            }
            public int GetItemHeight(IRibbonControl control)
            {
                return 68;
            }
            public int GetItemWidth(IRibbonControl control)
            {
                return 68;
            }
            public bool GetShowImage(IRibbonControl control)
            {
                return true;
            }



    • Edited by namwam Thursday, October 18, 2012 11:43 PM
    Thursday, October 18, 2012 11:40 PM

Answers

  • Hi nanwam

    I believe the problem is that you define an <item> element in your Ribbon XML:

             <gallery id="TestGallery" columns="1" rows="1" label="Test Gallery" getItemHeight="GetItemHeight" getItemWidth="GetItemWidth" getItemImage="GetItemImage" getShowImage="GetShowImage">
               
    <item id="item1" />

    As soon as you do that, your gallery becomes "static" and the dynamic attributes you define in the <gallery> element will not take effect. Your gallery must be either dynamic or static; it either contains no <item> elements (and all items are generated by callbacks) or you have to define each <item> individually in the XML, including the image using the image attribute of the item element.

    If you wan tthe gallery to be dynamic, you also need the attributes and callbacks for getItemCount and getItemID, the same as used for a comboBox element.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by namwam Saturday, October 20, 2012 3:40 AM
    Friday, October 19, 2012 2:02 PM
    Moderator

All replies

  • Hi nanwam

    I believe the problem is that you define an <item> element in your Ribbon XML:

             <gallery id="TestGallery" columns="1" rows="1" label="Test Gallery" getItemHeight="GetItemHeight" getItemWidth="GetItemWidth" getItemImage="GetItemImage" getShowImage="GetShowImage">
               
    <item id="item1" />

    As soon as you do that, your gallery becomes "static" and the dynamic attributes you define in the <gallery> element will not take effect. Your gallery must be either dynamic or static; it either contains no <item> elements (and all items are generated by callbacks) or you have to define each <item> individually in the XML, including the image using the image attribute of the item element.

    If you wan tthe gallery to be dynamic, you also need the attributes and callbacks for getItemCount and getItemID, the same as used for a comboBox element.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by namwam Saturday, October 20, 2012 3:40 AM
    Friday, October 19, 2012 2:02 PM
    Moderator
  • Cindy,

    Thank you for the help and explaining in precise details what a dynamic vs. static galley is and, in particular, what attributes are needed in order for a dynamic gallery to work. I took a big sigh of relief after acting upon your advice and seeing my code working.

    -Nam

    Saturday, October 20, 2012 3:39 AM
  • Hi Nam

    Thanks for letting us know that things are working, now :-)


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, October 20, 2012 6:12 AM
    Moderator