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

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

问题描述

对于使用C#4.0编程Office加载项,Microsoft提供了两种创建和/或修改Ribbon界面的方法:您可以使用 Ribbon Designer 或在 Ribbon XML



如果使用Ribbon设计器创建功能区,则在代码中生成的类可以查看您在功能区上放置的所有控件。所以如果我把一个名为dropdown1的RibbonDropDown,我可以使用下面的代码添加一个项目到它:

  RibbonDropDownItem item = Factory.CreateRibbonDropDownItem(); 
item.Label = submatrix.Name;
item.Tag = submatrix;
this.dropDown1.Items.Add(item);但是,如果使用Ribbon XML创建相同的功能区,则无法找到dropDown1或Factory()该名称在当前上下文中不存在)。



有没有办法访问在代码中添加到Ribbon XML定义功能区的项目?

解决方案

可能会晚一点,但希望这有助于某人。



<我对这个问题完全困惑。原来,你只能以字符串id的形式访问这些控件,并且模型对无效事件很重要。因此,例如,当您通过onAction方法获得按钮点击时,您只有来自控件对象的发件人ID,但是在此事件处理程序中,您可以使其他控件无效,并使用

$ b调用它们的事件
$ b

  ribbon.InvalidateControl(MyCtl); 

查看此 MS Lab ,它具有启动和运行所需的一切


For programming Office Add-ins using C# 4.0, Microsoft provides two different ways of creating and/or modifying the Ribbon interface: you can use the Ribbon Designer or define the Ribbon's layout in Ribbon XML.

If you create a ribbon using the Ribbon designer, the class generated in the code behind has visibility to all the controls you've placed on the ribbon. So if I've placed a RibbonDropDown called "dropdown1", I could use the following code to add an item to it:

RibbonDropDownItem item = Factory.CreateRibbonDropDownItem();
item.Label = submatrix.Name;
item.Tag = submatrix;
this.dropDown1.Items.Add(item);

However, if you create the same Ribbon using Ribbon XML, dropDown1 or Factory aren't found ("The name does not exist in the current context").

Is there a way to access the items added to a Ribbon XML-defined ribbon in code?

解决方案

Might be a little late, but hopefully this helps someone.

I was utterly confused about this same issue. Turns out, you can only access these controls as string ids, and the model is heavy on invalidation events. So for example, when you get a button click via onAction method, you only have the sender's id from the control object, however, in this event handler, you can invalidate the other controls and have their events called using

ribbon.InvalidateControl("MyCtl");

check out this MS Lab, it has everything you need to get up and running

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

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