I'm developing a Word Add-In with its own Ribbon tab. Most of my actual code is contain in some Service classes that get initialized in ThisAddIn_Startup and assigned to properties of the ThisAddIn singleton object. I also have an event listener that listens for clipboard events that I'd like to expose to the rest of the code as a property of the same object.
The problem that I'm running into is that the Load event of my Ribbon fires before the Startup event of ThisAddIn (even though the singleton object has already been initialized and assigned to Globals.ThisAddIn). In my Ribbon's Load event handler I would like to install a handler on that listener and also use one of those services. I can't, though, because at this point in program execution they're null.
What is the best solution to this issue? I could just make all of these things static members of ThisAddIn and initialize them in a static constructor, but that seems wrong and also destroys the whole point of having a Startup event (or a singleton object).
Oddly, I originally didn't have this problem when my Ribbon was just adding its components to the built-in Add-In tab - then the Load event fired after Startup.
(Note: I am doing all of this in Visual Studio 2012 and using the Ribbon designer.)
For this purpose i'm overriding BeginInit method. From my experience events occure in order (ribbon/initialization related):
I have tested the solution of tinamou, it doesn't work anymore. Ribbon_load indeed occurred after BeginInit but at this step the ribbon is fixed and read-only. There is no way to add groups buttons .. (it is however possible to modify dynamic menus).
I think the best way (stable) is to preload several groups etc.. and to use the visibility
property of controls to obtain a kind of dynamic ribbon.
See also this post localize VSTO addin according to the language of the office product,
it seems that CreateRibbonExtensibilityObject
is triggered at random times.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With