拦截 VSTO3 插件中的 GetCustomUI 回调

发布于 2024-09-30 10:59:21 字数 694 浏览 0 评论 0原文

我有一个 VSTO3 Word 插件,它使用自定义功能区和任务栏等。

现在,Office 2010 出现了,并且有一个漂亮的新 BACKSTAGE 概念,我想加入其中。但是,据我所知,使用 VSTO 执行此操作需要 Vsto 4,而 Vsto 4 需要 VS2010,而 VS2010 不是一个选项。

太棒了。我开始在网上查找,发现了各种示例,本质上是将后台 XML 搭载到我定义的任何 Ribbon xml 上,并将其作为 GetCustomUI 的值返回。一切都很好,除非您使用的是 VSTO3,否则似乎没有任何方法可以“挂钩”到 GetCustomUI 的调用链。这一切都由 OfficeRibbon 和 RibbonManage 类“自动”为您处理。

我知道我+可以+将插件转换为共享插件,然后直接实现 IDTExtensibility 接口。我会失去所有 vsto 的优点(是的,这是有争议的),但我会获得对 GetCustomUI 调用的访问权限。

有人尝试过使用 VSTO +WHILE+ 访问 GetCustomUI 吗?有可能吗?

我以为我可以为 RibbonManager 创建一个包装类,但是瞧,MS 已经做了一些看起来严重违反封装的事情。 RibbonManager 实现了漂亮且简单的 IRibbonExtensibility 接口,但是,在传递该接口的地方,它们实际上检查传递的对象以确保它是实际类型 RibbonManager!呃,关于任何类型的包装纸就这么多了。

I've got a VSTO3 Word addin that makes use of custom ribbons and taskbars, etc.

Now, Office 2010 comes along and there's this nifty new BACKSTAGE concept, which I'd like to hook into. However, from what I can tell, doing it with VSTO requires Vsto 4, which requires VS2010, which isn't an option.

Soooo. I started looking online and have found all sorts of examples of, essentially, piggybacking the backstage XML onto whatever Ribbon xml I define and returning that as the value of GetCustomUI. All good, except if you're using VSTO3, there doesn't appear to be any way to "hook" into the call chain for GetCustomUI. It's all "automagically" handled for you by the OfficeRibbon and RibbonManage classes.

I know I +COULD+ convert the addin to a shared addin and just implement the IDTExtensibility interfaces directly. I'd lose all the vsto goodness (yeah, that's debatable) but I'd gain access to the GetCustomUI call.

Anyone every tried to get access to GetCustomUI +WHILE+ using VSTO though? Is it even possible?

I thought I could create a wrapper class for RibbonManager, but lo, MS has gone and done what looks to be some supreme violation of encapsulation. The RibbonManager implements the nice and easy IRibbonExtensibility interface, and yet, where that interface is passed around, they actually check the passed object to be sure it's of the actual type RibbonManager! Ugh, so much for any kind of wrapper.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

π浅易 2024-10-07 10:59:21

事实证明这是可能的,只是不容易。您必须在连接时重写 CreateRibbonExtensibilityObject 方法,以及 CreateRibbonObjects 和 RequestService 方法。

然后,您必须创建一个对象来包装内置的 VSTO RibbonManager 对象,并实现 iReflect 来拦截反射 INVOKE 调用并将其转发到底层 RibbonManager。

最后,在拦截器对象上,您还必须实现 IRibbonExtensibility,然后编写该接口的 GetCustomUI 方法。

完成所有这些操作后,您的 GetCustomUI 将被调用并传入您通过 VSTO 定义的功能区的完整 XML,然后您可以直接更改它(在我的情况下,我需要添加后台支持),然后返回该 xml从函数。

绝对不是直截了当的,但它确实有效。

Turns out it's possible, just not easy. You have to override the CreateRibbonExtensibilityObject method on connect, as well as the CreateRibbonObjects, and the RequestService methods.

Then, you have to create an object that wraps the built in VSTO RibbonManager object, and implements iReflect to intercept reflection INVOKE calls and forward them on to the underlying RibbonManager.

Finally, on the interceptor object, you have to also implement IRibbonExtensibility, then code up the GetCustomUI method of that interface.

once you do all that, your GetCustomUI will be called and passed in the full XML of the ribbons you've defined via VSTO, which you can then alter directly (in my case I needed to add backstage support), and then return that xml from the function.

definitely not straightforward, but it works.

顾忌 2024-10-07 10:59:21

如果您想在 VSTO 应用程序中运行时编辑 XML 功能区,我在这里创建了一个简单的解决方案: 使用 VS2010 在 .NET 中自定义 Outlook 2007 功能区; insertBeforeMso 动态函数

If you want to edit XML ribbon at runtime in a VSTO app, I have created a simple solution here: Outlook 2007 ribbon customization in .NET using VS2010; insertBeforeMso dynamic function

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文