[英]The ribbon added to a VSTO for Excel is of type RibbonBase and not IRibbonExtensibility
I am building a VSTO application (WinForms) and following the instructions at:我正在构建一个 VSTO 应用程序 (WinForms) 并按照以下说明进行操作:
https://docs.microsoft.com/en-us/visualstudio/vsto/walkthrough-creating-a-custom-tab-by-using-ribbon-xml?view=vs-2019 https://docs.microsoft.com/en-us/visualstudio/vsto/walkthrough-creating-a-custom-tab-by-using-ribbon-xml?view=vs-2019
The steps are shown below:步骤如下所示:
When I add the CreateRibbonExtensibilityObject()
code in step 5 (shown below):当我在步骤 5 中添加CreateRibbonExtensibilityObject()
代码时(如下所示):
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new MyRibbon();
}
I get the following error:我收到以下错误:
Cannot implicitly convert the type MyRibbon to Microsoft.Office.Core.IRibbonExtensibility. An explicit conversion exists (are you missing a cast)?
The class generated by Visual Studion is of type RibbonBase
. Visual Studion 生成的 class 是RibbonBase
类型。
partial class CLIREMPRibbon : Microsoft.Office.Tools.Ribbon.RibbonBase {...}
A type-cast below throws an exception:下面的类型转换会引发异常:
Unable to cast object of type MyRibbon to type Microsoft.Office.Core.IRibbonExtensibility.
How would I apply the correct type cast of a RibbonBase to a IRibbonExtensibility interface instance?如何将 RibbonBase 的正确类型转换应用于 IRibbonExtensibility 接口实例?
In VSTO, you can create a basic custom Fluent UI using a visual designer and then export it to a ribbon XML file which can be extended after.在 VSTO 中,您可以使用可视化设计器创建基本的自定义 Fluent UI,然后将其导出到功能区 XML 文件,之后可以进行扩展。 Not all features are available in the ribbon designer, unfortunately, so sometimes you have to switch to using the raw XML markup instead.不幸的是,功能区设计器中并非所有功能都可用,因此有时您必须改用原始 XML 标记。 Read more about that in the How to: Export a ribbon from the Ribbon Designer to Ribbon XML article.在如何:将功能区从功能区设计器导出到功能区 XML文章中了解更多信息。 So, if you are fine with a designer, there is no need to modify anything in the code.因此,如果您对设计人员感到满意,则无需修改代码中的任何内容。 You have to choose one or another way of customizing the Fluent UI.您必须选择一种或另一种方式来自定义 Fluent UI。
See:看:
https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.tools.addinbase.createribbonextensibilityobject?view=vsto-2017 https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.tools.addinbase.createribbonextensibilityobject?view=vsto-2017
" You do not have to override this method to return Ribbons that you add to the project by using the Ribbon (Visual Designer) item template . “您不必重写此方法来返回使用功能区(可视化设计器)项目模板添加到项目中的功能区。
By default, this method returns a RibbonManager object that represents all Ribbon (Visual Designer) items in the project.默认情况下,此方法返回一个 RibbonManager object,它代表项目中的所有 Ribbon(可视化设计器)项。 For more information, see Ribbon Overview."有关详细信息,请参阅功能区概述。”
I had switched from XML to using the Visual Designer so that I could add an Active Panel.我已从 XML 切换到使用可视化设计器,以便添加活动面板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.