简体   繁体   English

在XML功能区中以编程方式访问功能区元素

[英]Access Ribbon Elements Programmatically in XML Ribbon

This seems to have been asked several times on here with no real answer: 这似乎已经多次被问到这里没有真正的答案:

Accessing Ribbon Controls Programatically in an XML Ribbon 在XML功能区中以编程方式访问功能区控件

Office Ribbon: How to access a control when the ribbon was created using XML Office功能区:如何在使用XML创建功能区时访问控件

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. 如果使用功能区xml创建功能区,据我所知,没有编程在该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). 改变这些组件状态的唯一明显有限的方法是使用像onAction,getContent,getImage事件这样的东西,并且IRibbonControl元素对于操纵有问题的元素提供的很少(更不用说,大多数这些函数只运行一次) ,首次渲染时)。

So I'm trying to find a way to programmatically access those xml ribbon elements. 所以我试图找到一种以编程方式访问这些xml功能区元素的方法。

There is no way to programmatically access Ribbon elements when using Ribbon XML. 使用Ribbon XML时,无法以编程方式访问Ribbon元素。 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 ). 如果要更改功能区控件的状态 - 需要使用IRibbonUI.Invalidate()强制新的布局呈现( 可能使用通过回调在渲染时触发不同行为的属性 )。 This can be a good thing as you have more control over when drawing occurs if you are changing multiple items' state. 这可能是一件好事,因为如果要更改多个项目的状态,您可以更好地控制何时进行绘制。

See related SO post on updating Ribbon UI control state. 请参阅有关更新功能区UI控件状态的相关SO帖子

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. 但是,如MSDN所述,设计人员不支持所有自定义。 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. 您只需要学习Ribbon XML使用回调机制 - 没有控制树可供您访问。

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

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