在 XML 功能区中以编程方式访问功能区元素 [英] Access Ribbon Elements Programmatically in XML Ribbon

查看:26
本文介绍了在 XML 功能区中以编程方式访问功能区元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎在这里被问过几次,但没有真正的答案:

This seems to have been asked several times on here with no real answer:

在 XML 功能区中以编程方式访问功能区控件

Office功能区:如何在使用 XML 创建功能区时访问控件

如果功能区是使用功能区 xml 创建的,据我所知,该 xml 中定义的组件不会以编程方式公开.更改这些组件状态的唯一明显受限的方法是使用诸如 onAction、getContent、getImage 事件之类的东西,而 IRibbonControl 元素几乎没有提供操作相关元素的功能(更不用说,大多数这些功能只运行一次, 首次渲染时).

If a ribbon is created using ribbon xml, as far as I can tell, there is no programmatic exposure of the components defined in that xml. The only obvious limited way to change the state of these components is to use something like an onAction, getContent, getImage event, and the IRibbonControl element offers very little for manipulating the element in question (not to mention, most of those functions only run once, when first rendered).

所以我试图找到一种方法来以编程方式访问这些 xml 功能区元素.

So I'm trying to find a way to programmatically access those xml ribbon elements.

推荐答案

在使用 Ribbon XML 时无法以编程方式访问 Ribbon 元素.如果您想更改 Ribbon 控件的状态 - 您需要使用 IRibbonUI.Invalidate() 强制重新渲染布局(可能使用在渲染时触发不同行为的属性通过回调).这可能是一件好事,因为如果您要更改多个项目的状态,您可以更好地控制何时发生绘制.

There is no way to programmatically access Ribbon elements when using Ribbon XML. If you want to change the state of the Ribbon controls - you need to use IRibbonUI.Invalidate() to force a new rendering of the layout (potentially using properties that trigger different behaviors at rendering time via callbacks). This can be a good thing as you have more control over when drawing occurs if you are changing multiple items' state.

请参阅关于更新功能区 UI 控件状态的相关 SO 帖子.

See related SO post on updating Ribbon UI control state.

如果您想以编程方式访问 Ribbon 元素,则应使用 Ribbon Designer.但是,正如 在 MSDN 上所述,设计者并不支持所有定制.一些推测设计者只是在下面为您包装了 Ribbon XML引擎盖.

If you want programmatic access to Ribbon elements, you should use the Ribbon Designer. However, as stated on MSDN, the designer doesn't support all customizations. Some speculate that the designer just wraps the Ribbon XML up for you under the hood.

您只需要了解 Ribbon XML 使用的回调机制 - 没有可供您访问的控制树.

You just have to learn the callback mechanism utilized by the Ribbon XML - there is no control tree for you to gain access to.

这篇关于在 XML 功能区中以编程方式访问功能区元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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