Access Ribbon Elements Programmatically in XML Ribbon

梦想与她 提交于 2019-11-28 07:46:10

问题


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

Accessing Ribbon Controls Programatically in an XML Ribbon

Office Ribbon: How to access a control when the ribbon was created using 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. 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).

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


回答1:


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.

See related SO post on updating Ribbon UI control state.

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.

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



来源:https://stackoverflow.com/questions/9353151/access-ribbon-elements-programmatically-in-xml-ribbon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!