无法填充 RibbonMenu
我需要在运行时使用数据库中的一些数据填充 RibbonMenu 控件。
我的偏移量为: http:// /msdn.microsoft.com/en-us/library/microsoft.office.tools.ribbon.ribbonmenu(v=vs.90).aspx
与代码:
private void PopulateCustomerMenu()
{
// Add two sub-menus to EmployeeMenu and populate each sub-menu
// First sub-menu
RibbonMenu subMenu1 = new RibbonMenu(); //new RibbonMenu(); is underlined red
subMenu1.Dynamic = true;
subMenu1.Label = "A - M";
subMenu1.Items.Add(new RibbonToggleButton()); //new RibbonToggleButton() is as well
((RibbonToggleButton)subMenu1.Items.Last()).Label = "Hall, Don";
subMenu1.Items.Add(new RibbonToggleButton()); //new RibbonToggleButton() is as well
((RibbonToggleButton)subMenu1.Items.Last()).Label = "Valdez, Rachel";
CustomerMenu.Items.Add(subMenu1);
// Second sub-menu
RibbonMenu subMenu2 = new RibbonMenu(); //new RibbonMenu(); is as well
subMenu2.Dynamic = true;
subMenu2.Label = "N - Z";
subMenu2.Items.Add(new RibbonToggleButton()); //new RibbonToggleButton() is as well
((RibbonToggleButton)subMenu2.Items.Last()).Label = "Robinson, Alex";
CustomerMenu.Items.Add(subMenu2);
}
我得到的唯一东西是视觉Studio 显示“错误 1 无法创建抽象类或接口“Microsoft.Office.Tools.Ribbon.RibbonMenu”的实例 C:\Users\Christoffer\Documents\Visual Studio 2010\Projects\OutlookAddIn2\OutlookAddIn2\Ribbon1。 cs 80 35 OutlookAddIn2"
我在过去 15 个小时里一直被困,所以我愿意接受任何事情......任何想法?
I need to populate a RibbonMenu control at run-time, with some data from a database.
I take my offset in:
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.ribbon.ribbonmenu(v=vs.90).aspx
with the code:
private void PopulateCustomerMenu()
{
// Add two sub-menus to EmployeeMenu and populate each sub-menu
// First sub-menu
RibbonMenu subMenu1 = new RibbonMenu(); //new RibbonMenu(); is underlined red
subMenu1.Dynamic = true;
subMenu1.Label = "A - M";
subMenu1.Items.Add(new RibbonToggleButton()); //new RibbonToggleButton() is as well
((RibbonToggleButton)subMenu1.Items.Last()).Label = "Hall, Don";
subMenu1.Items.Add(new RibbonToggleButton()); //new RibbonToggleButton() is as well
((RibbonToggleButton)subMenu1.Items.Last()).Label = "Valdez, Rachel";
CustomerMenu.Items.Add(subMenu1);
// Second sub-menu
RibbonMenu subMenu2 = new RibbonMenu(); //new RibbonMenu(); is as well
subMenu2.Dynamic = true;
subMenu2.Label = "N - Z";
subMenu2.Items.Add(new RibbonToggleButton()); //new RibbonToggleButton() is as well
((RibbonToggleButton)subMenu2.Items.Last()).Label = "Robinson, Alex";
CustomerMenu.Items.Add(subMenu2);
}
The only thing I get is Visual Studio saying "Error 1 Cannot create an instance of the abstract class or interface 'Microsoft.Office.Tools.Ribbon.RibbonMenu' C:\Users\Christoffer\Documents\Visual Studio 2010\Projects\OutlookAddIn2\OutlookAddIn2\Ribbon1.cs 80 35 OutlookAddIn2"
I have been stuck for the last 15 hours, so I'm open for anything.... Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有趣的是,有一个接口和一个类,两者具有相同的名称,但位于不同的 dll 中。如果您查看此处的文档页面 您会看到以下有关界面位置的信息:
在您链接到的页面上有:
您链接到的版本来自 Visual Studio 2007 版本(因此链接中的 v=vs90。如果您尝试使用该版本,请确保正确的 dll (Microsoft.Office.Tools.Common.v9.0.dll) 正在被您的项目引用,而不是新的 dll (Microsoft.Office.Tools.Common.dll)
如果您想使用新的 dll,则在为了创建菜单或菜单项,您必须获取 RibbonFactory 基于您构建功能区的位置。例如,如果您尝试向 Word 添加功能区菜单,您将调用
Globals.Factory.GetRibbonFactory()
,然后使用此调用返回的工厂来创建您的功能区。Interestingly enough there is an interface and there is a class both with the same name that are in different dll's. If you look at the documentation page here you see the following information about the loaction of the interface:
On the page you linked to you have:
The one you linked to is from the Visual Studio 2007 edition (hence the v=vs90 in the link. If you are trying to use that version then make sure the proper dll (Microsoft.Office.Tools.Common.v9.0.dll) is being referenced by your project and not the new dll (Microsoft.Office.Tools.Common.dll)
If you want to use the new dll then in order to create menu or menu items you must get an instance of the RibbonFactory based upon where you are building the Ribbon. For example if you were trying to add a Ribbon menu to Word you'd call
Globals.Factory.GetRibbonFactory()
and then use the factory returned by this call to create your Ribbon.