Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

c# - Is there a way to access a Ribbon (XML) at run time?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...