简体   繁体   English

VSTO Outlook 插件功能区未正确加载

[英]VSTO Outlook Addin Ribbons not loading properly

I'm currently reparing an Outlook VSTO Addin.我目前正在修复 Outlook VSTO 插件。 The project contains 4 ribbons with their respective Ribbon Type:该项目包含 4 个功能区及其各自的功能区类型:

  • CrmAppointmentRibbon.cs -> Type: Microsoft.Outlook.Appointment CrmAppointmentRibbon.cs -> 类型:Microsoft.Outlook.Appointment
  • CrmEmailNewRibbon.cs -> Type: Microsoft.Outlook.Mail.Compose CrmEmailNewRibbon.cs -> 类型:Microsoft.Outlook.Mail.Compose
  • CrmEmailReadRibbon.cs -> Type: Microsoft.Outlook.Mail.Read CrmEmailReadRibbon.cs -> 类型:Microsoft.Outlook.Mail.Read
  • CrmEmailRibbon.cs -> Type: Microsoft.Outlook.Mail.Explorer CrmEmailRibbon.cs -> 类型: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:因此,当 Outlook 打开时,调用方法 ThisAddIn_Startup 来初始化插件,我得到的功能区集合如下:

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.因此,ribbonCollection 包含 4 个功能区,但ribbonCollection 的CrmEmailRibbon 变量的class 类型不匹配。 When I do当我做

ribbonCollection.CrmEmailRibbon

It returns the CrmEmailReadRibbon instead of CrmEmailRibbon.它返回 CrmEmailReadRibbon 而不是 CrmEmailRibbon。 So the CrmEmailReadRibbon is returned twice.所以 CrmEmailReadRibbon 被返回两次。 It's the same ribbon returned from this two calls:这是从这两个调用返回的相同功能区:

ribbonCollection.CrmEmailRibbon
ribbonCollection.CrmEmailReadRibbon

The first call should return its associated ribbon reference: CrmEmailRibbon.第一次调用应返回其关联的功能区引用:CrmEmailRibbon。 Because of that I cannot access to the groups and buttons of the CrmEmailRibbon... Did somebody encounter this behaviour?因此,我无法访问 CrmEmailRibbon 的组和按钮......有人遇到过这种行为吗?

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:您将获得检查器 window 的功能区实例,它可以是以下之一:

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).但我建议使用功能区回调而不是使用 VSTO object model 来处理功能区 UI(又名功能区 UI)。 Moreover, VSTO doesn't provide all features of the Fluent UI.此外,VSTO 并未提供 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.有时您必须使用功能区设计器创建基本 UI,然后将其导出到功能区 XML 文件,您可以在其中开始使用回调。

As my colleague stated, the Ribbon UI is a static thing from its birth.正如我的同事所说,功能区 UI 从一开始就是 static 的东西。 The only possible dynamism is callbacks and menu.唯一可能的动态是回调和菜单。 So, you may compare both approaches:因此,您可以比较两种方法:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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