有没有办法在运行时访问功能区(XML)?

发布于 2024-11-03 19:42:08 字数 387 浏览 4 评论 0原文

我正在开发 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?

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

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

发布评论

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

评论(3

捶死心动 2024-11-10 19:42:08

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

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

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

干杯,
杰克

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).

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.

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.

Cheers,
Jake

人│生佛魔见 2024-11-10 19:42:08

使用 Ribbon XML 时,我尝试了此操作,但无法从 Globals.Ribbons 访问 Ribbon1 属性。简单的属性不存在。

但是,我想出了另一个解决方案,该解决方案基本上与正确的解决方案有关类型转换。

在 ThisAddIn.cs 中:

private Microsoft.Office.Core.IRibbonExtensibility ribbonObj;
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
 ribbonObj = new Ribbon1(this);
 return ribbonObj;
}

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{ 
 // Calling the public method TEST() in Ribbon1.cs 
 //MyNameSpace is the namespace used in your project ie., your project name 
 ((MyNameSpace.Ribbon1)ribbonObj).TEST();
 // Calling the public variable flag in Ribbon1.cs  
 ((MyNameSpace.Ribbon1)ribbonObj).flag;
}

When working with Ribbon XML, I tried this but I couldn't access the Ribbon1 property from the Globals.Ribbons.. The property simple wasn't there..

However, I came up with another solution which basically had to do with a proper type cast.

In ThisAddIn.cs:

private Microsoft.Office.Core.IRibbonExtensibility ribbonObj;
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
 ribbonObj = new Ribbon1(this);
 return ribbonObj;
}

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{ 
 // Calling the public method TEST() in Ribbon1.cs 
 //MyNameSpace is the namespace used in your project ie., your project name 
 ((MyNameSpace.Ribbon1)ribbonObj).TEST();
 // Calling the public variable flag in Ribbon1.cs  
 ((MyNameSpace.Ribbon1)ribbonObj).flag;
}
冬天的雪花 2024-11-10 19:42:08

这取决于您何时尝试访问 Globals.ribbons。

我记得,直到 Word 启动阶段即将结束时才会填充它。

如果您尝试过早访问它,则还不会定义任何功能区。

It depends on when you are trying to access Globals.ribbons.

As I recall, it won't be populated until very near the end of the start up phase of Word.

if you try and access it too early, there won't be any ribbons defined yet.

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