0

I have an VSTO Office/Outlook add-in and ribbon that I want to reload at some point. Unfortunatelly ribbon.invalidate is not something that suits my case, because it just re-fires getLabel etc. methods, while I need to rebuild whole ribbon/group.

I need to force executing method GetCustomUI().

Do you know how can I do it?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
buks
  • 405
  • 1
  • 6
  • 21

2 Answers2

3

There is no way to force Office applications invoke the GetCustomUI callback. If you need to keep your custom ribbon UI hidden at startup by default you can use the getVisible callback for the ribbon controls, including tabs, and when required you may call the IRibbonUI.Invalidate to get your controls callback invoked, so you could return an appropriate value and get your controls appeared on the ribbon.

For example, if an add-in writer implements the getVisible callback procedure for a button, the function is called once, the state loads, and then if the state needs to be updated, the cached state is used instead of recalling the procedure. This process remains in place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Thanks for the reply. I do not want to keep it hidden, I just want to change its content. So, in general, that what I wanted to do, seems to be impossible. I wanted to have a split button with menu and that menu with dynamic list of items. Somebody can say, hey! There is dynamicmenu. Yes, there is, but it can not be a child element of splitbutton... – buks Feb 08 '23 at 14:41
  • The ribbon UI is a static thing except several controls that can created dynamically. There is no way to re-build the ribbon XML and update it on demand. You must provide the custom UI at the host startup when the `GetCustomUI` method is called by the Office. – Eugene Astafiev Feb 08 '23 at 14:47
0

No way to do that - by design, Ribbon is static, even though some controls can be hidden initially and be shown later when their getVisible callback is invoked.

Note that control contents can be populated dynamically (sounds like that is what you actually want), that applies to the dropDown control. In that case, you need to specify getItemCount/getItemLabel/getItemImage/getSelectedItemIndex callbacks.

See the dropDown control description on MSDN: https://learn.microsoft.com/en-us/openspecs/office_standards/ms-customui/700e4451-8706-40c5-8d7b-896e4ae21b69

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78