简体   繁体   中英

VSTO Outlook Addin Ribbons not loading properly

I'm currently reparing an Outlook VSTO Addin. The project contains 4 ribbons with their respective Ribbon Type:

  • CrmAppointmentRibbon.cs -> Type: Microsoft.Outlook.Appointment
  • CrmEmailNewRibbon.cs -> Type: Microsoft.Outlook.Mail.Compose
  • CrmEmailReadRibbon.cs -> Type: Microsoft.Outlook.Mail.Read
  • CrmEmailRibbon.cs -> Type: Microsoft.Outlook.Mail.Explorer

So when Outlook opens, the method ThisAddIn_Startup is called to initialize the Addin and I'm getting the ribbon collection as follows:

ThisRibbonCollection ribbonCollection = Globals.Ribbons[Globals.ThisAddIn.Application.ActiveInspector()];

So the ribbonCollection contains the 4 ribbons but there is a mismatch concerning the class type of the CrmEmailRibbon variable of the ribbonCollection. When I do

ribbonCollection.CrmEmailRibbon

It returns the CrmEmailReadRibbon instead of CrmEmailRibbon. So the CrmEmailReadRibbon is returned twice. It's the same ribbon returned from this two calls:

ribbonCollection.CrmEmailRibbon
ribbonCollection.CrmEmailReadRibbon

The first call should return its associated ribbon reference: CrmEmailRibbon. Because of that I cannot access to the groups and buttons of the CrmEmailRibbon... Did somebody encounter this behaviour?

By running the following code:

ThisRibbonCollection ribbonCollection = Globals.Ribbons[Globals.ThisAddIn.Application.ActiveInspector()];

You get a ribbon instance for the inspector window which can be one of the following:

CrmAppointmentRibbon.cs -> Type: Microsoft.Outlook.Appointment
CrmEmailNewRibbon.cs -> Type: Microsoft.Outlook.Mail.Compose
CrmEmailReadRibbon.cs -> Type: Microsoft.Outlook.Mail.Read

To get the ribbon instance you need to pass an active explorer instance:

ThisRibbonCollection ribbonCollection = Globals.Ribbons[Globals.ThisAddIn.Application.ActiveExplorer()];

for the following instance:

CrmEmailRibbon.cs -> Type: Microsoft.Outlook.Mail.Explorer

Depending on the context you will get the appropriate ribbon instance.


But I'd suggest using ribbon callbacks instead of using the VSTO object model for dealing with the Ribbon UI (aka Ribbon UI). Moreover, VSTO doesn't provide all features of the Fluent UI. Sometimes you have to create a basic UI using the ribbon designer and then export it to a ribbon XML file where you could start using callbacks.

As my colleague stated, the Ribbon UI is a static thing from its birth. The only possible dynamism is callbacks and menu. So, you may compare both approaches:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM