有没有办法在运行时访问功能区 (XML)? [英] Is there a way to access a Ribbon (XML) at run time?

查看:37
本文介绍了有没有办法在运行时访问功能区 (XML)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Word 2007 应用级加载项.到目前为止,除了将加载项的 Ribbon 界面转换为 XML 之外,我还没有遇到重大障碍.我必须使用 Ribbon XML,因为我正在处理的功能只能通过这种方式完成.问题是,通过切换到 Ribbon XML,我无法在运行时通过 Globals.Ribbons 访问界面.此链接 http://msdn.microsoft.com/en-us/library/bb772088.aspx 很好地解释了如何访问可视化设计器功能区,但它完全忽略了 XML 功能区案例.具体来说,我需要能够访问一些视觉控件,例如标签.我怎样才能做到这一点?

I'm working on a Word 2007 app-level add-in. So far, I haven't experienced major obstacles except for converting the add-in's Ribbon interface to XML. I have to use Ribbon XML because the feature I'm working on can only be done this way. The problem is that by switching to Ribbon XML I can no longer access the interface at run time via Globals.Ribbons. This link http://msdn.microsoft.com/en-us/library/bb772088.aspx does a good job explaining how to access a Visual Designer Ribbon but it completely ignores the XML Ribbon case. Specifically, I need to be able to access some visual controls such as labels. How can I achieve this?

推荐答案

Globals.Ribbons 是 VSTO 设计器的一个功能,如果你使用 RibbonXML 那么你就没有这个功能.设计者实际上在幕后所做的是为 Office 创建 Ribbon xml,然后当 office 进行回调时,VSTO 将为该上下文(文档)引发适当的事件处理程序.因为您使用的是 RibbonXML,所以您完全绕过了 VSTO Ribbon 设计器支持(我更喜欢这种方式,它更快并且您拥有更多控制权).

Globals.Ribbons is a VSTO designer feature, if you use RibbonXML then you don't have this feature. What the designer actually does under the covers is it will create ribbon xml for Office, then when office makes a callback, VSTO will raise the appropriate event handler for that context (document). Because you are using RibbonXML you are bypassing the VSTO Ribbon designer support entirely (I prefer it this way, it is faster and you have more control).

使用功能区 XML,您必须为标签注册一个 onLoad 回调,然后 Office 将传递给您一个 IRibbonControl,这将是标签,您可以做的事情有限.如果您想更改文本,那么您必须注册一个 getText 回调,然后使该功能区控件无效,这将导致重新评估 getText 回调.

With ribbon XML you will have to register a onLoad callback for your label, Office will then pass you a IRibbonControl, which will be the label, and you have limited stuff you can do. If you wanted to change the text then off the top of my head you would have to register a getText callback, then invalidate that ribbon control, which will cause the getText callback to be reevaluated.

获得有关您实际想要实现的目标的更多信息会很方便 =) 我有一种感觉,我的 VSTO contrib 项目也会让您的生活变得更轻松,因为它在使用 Ribbon xml 时为您提供了许多不错的 Ribbon Designer 功能.但请告诉我您想做什么,我可以为您提供更多相关信息.

Having more info about what you actually want to achieve would be handy =) I have a feeling my VSTO contrib project will also make your life much easier, as it gives you many of the nice Ribbon Designer features when using ribbon xml. But let me know what it is you want to do, and I can give you more info about that.

干杯,杰克

这篇关于有没有办法在运行时访问功能区 (XML)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆