If your are stucked as you have already built VSTO application by using Ribbon designer but as mentioned in previous topics, Ribbon designer is not capable enough to cop-up all your ribbon customization needs like creating Menu Buttons, Context Menus etc. And you are end up with empty hand seeking help. Now you have no choice than creating entire ribbon design from scratch using Ribbon XML. No worries here is the solution to grab your existing ribbon design into XML which you can take for your next level development.
Prerequisites:
- Visual studio 2010 or above
- A Office Adding Project (Visual Studio Tools for Office)
To export a Ribbon from the Ribbon Designer to Ribbon XML
- Right-click the Ribbon code file in Solution Explorer, and then click View Designer.
- Right-click the Ribbon Designer, and then click Export Ribbon to XML.
- Visual Studio adds a Ribbon XML file and a Ribbon XML code file to your project.
- In the Ribbon code class, locate the comments that start with TODO:.
- Copy the code block in these comments to the ThisAddin, ThisWorkbook, or ThisDocument class, depending on which type of solution you are developing.
- This code enables the Microsoft Office application to discover and load your custom Ribbon. For more information, see Ribbon XML.
- In the ThisAddin, ThisWorkbook, or ThisDocument class, un-comment the code block.
After you un-comment the code, it should resemble the following example. In this example, the Ribbon class is called MyRibbon.
Code example:
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject() { return new MyRibbon(); }
- Switch to the Ribbon XML code file and find the Ribbon Callbacks region.
- This is where you write callback methods to handle user actions, such as clicking a button.
- Create a callback method for each event handler that you wrote in the Ribbon Designer code.
- Move all your event handler code from the event handlers to the callback methods, and modify the code to work with the Ribbon extensibility (RibbonX) programming model.
Next>>Accessing the Ribbon at Run Time