Search code examples
c#vstooffice-interopoffice-addins

How can I fix No loadImage callback was specified to load the image with id error


How can I fix No loadImage callback was specified to load the image with id error. I need to use xml string dynamically like this. how can i add the picture. enter image description here


Solution

  • If you use the image attributes in the ribbon XML markup you need to specify the loadImage attribute for the customUI tag.


    There are two major ways for loading images in the Fluent UI:

    1. The <customUI> element's loadImage attribute enables you to specify a callback that can load all images. After you set up this callback procedure, Office calls the callback procedure and passes the string from the image attribute for each control that loads images. You do not need to implement the getImage callback multiple times, such as one time for each control that requires images. For example, a customization might include markup like the following.
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
      loadImage="GetImage">
    <!-- Later in the markup -->
       <button id="myButton" image="mypic.jpg" />
    

    To supply the button's image, Office calls the GetImage function. It passes the parameter "mypic.jpg" and expects an IPictureDisp object in return. By using this technique, you can write a single callback procedure that returns all the images your customization needs, without having to write each individual control's getImage callback. Note that the loadImage callback is not called again when you call the Ribbon's Invalidate method or InvalidateControl method. For the controls that need to change images dynamically at run time, use the getImage callback.

    1. The getImage attribute for controls which allows specifying a callback to load images dynamically.

    Read more about that in the following series of articles in MSDN: