I am working on an Outlook 2010 add-in with several ribbons created using the Visual Studio 2010 ribbon designer. I made an additional XML ribbon (I needed to override the default behavior of some built-in ribbon buttons, which cannot be done with the designer).
Enabling XML feeds disables all designer feeds because I need to override CreateRibbonExtensibilityObject (ContactButtonOverrides is my XML feed):
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject() { return new ContactButtonOverrides(); }
The implementation of the base class I override returns the RibbonManager object, which represents all the Ribbon elements (Visual Designer) in the project .
Can I use both XML ribbons and designer ribbons? Is there any way to add XML ribbon to RibbonManager by default?
You cannot use the Ribbon Designer and XML Ribbon unless you use (2) separate add-ons. IAddInExtension.CreateRibbonExtensibilityObject is called only once for the life cycle of your add-in. You can either implement the interface using the Constructor or XML . These are two separate API hooks.
IAddInExtension.CreateRibbonExtensibilityObject
Designer Ribbon Designer is more like a crutch for new Office Ribbon developers. Once you become familiar with Ribbon XML ) it is much simpler and you have much more control over the behavior (as you specify in your OP). You can transfer from Ribbon Designer to XML using the context menu from the surface of the ribbon designer - although there are several redistributions for images and callbacks , because the model is completely different. Itβs worth your time to invest in Ribbon XML , since this is a way to expand context menus ( CommandBars deprecated) and Backstage View, since there is no designer .
CommandBars
Then in ContactButtonOverrides ... you can run which XML to load via IRibbonExtensibility.GetCustomUI , which passes into the Ribbon ID Type ...
ContactButtonOverrides
IRibbonExtensibility.GetCustomUI
public string GetCustomUI(string ribbonID) { switch (ribbonID) { case "Microsoft.Outlook.Appointment" : return GetResourceText("OutlookRibbonApp.IPM.Appointment.Ribbon.xml"); case "Microsoft.Outlook.Mail.Compose" : return GetResourceText("OutlookRibbonApp.IPM.Note.Ribbon.xml"); default: return ""; } }
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject() { if (myCondition == true) { return Globals.Factory.GetRibbonFactory().CreateRibbonManager( new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { new Ribbon1() }); } else { return Globals.Factory.GetRibbonFactory().CreateRibbonManager( new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { new Ribbon2() }); } }