步骤 8(可选):定义功能区和操作 (Ribbon.xml)
现在,您已将任务窗格布局添加到中间声明性 Outlook 解决方案,还可以添加自定义功能区文件定义。功能区文件指定从功能区调用的操作。
上次修改时间: 2011年8月22日
适用范围: SharePoint Server 2010
例如,许多解决方案在功能区上都有一个按钮,可用于打开任务窗格。打开任务窗格的行为可以为一个操作。功能区文件使用所有 Microsoft Office 应用程序使用的标准功能区架构。
Business Connectivity Services 中的操作可以基于 URL 或基于代码。基于 URL 的操作在执行时(例如,单击功能区按钮时)会导航至指定的 URL。基于 URL 的操作可在 Ribbon.xml 文件中以声明方式进行定义。代码操作在单击功能区按钮时执行代码,并且必须在使用之前由开发人员创建。
代码示例:AdventureWorks2008 声明性 Outlook 解决方案具有一个自定义功能区菜单,"Contoso Sales Manager"。在单击"Contoso Sales Manager"时,将显示如下两个功能区按钮:
相关订单 单击该按钮时,将在任务窗格中显示订单历史记录。
电话查询 单击该按钮时,将在浏览器窗口中打开 MSN 电话查询页面并搜索客户的电话号码。
创建功能区文件
您可以使用 BCS 项目生成器工具(该链接可能指向英文页面)基于 BDC 模型创建窗体区域清单文件。
您还可以手动创作窗体区域清单,方法如下。
找到 SDK 中提供的模板:Ribbon.xml,复制后将其保存到 Solution Artifacts 文件夹,并命名为 OutlookContactRibbon.xml。
在 XML 编辑器中打开 OutlookContactRibbon.xml 文件进行编辑。如果是在 Visual Studio 中打开 XML 文件,请附上 Office 功能区架构(Office 2010 参考:Office Fluent 用户界面 XML 架构(该链接可能指向英文页面))。这会为您提供 IntelliSense 功能并有助于您创建有效的条目。
将 XML 中标有 EnterX 的值替换为有效值。下面的 XML 示例演示了文件在编辑后的外观。
<customUI xmlns="https://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoad" loadImage="GetImage"> <ribbon> <tabs> <tab id="tabID" label="Contoso Sales Manager" getVisible="GetVisible" tag="Solution"> <group id="CustomerSalesGroupID" label="Customer Sales" getVisible="GetVisible" tag="Context[OutlookContactCustomer.CustomerSalesGroupID]"> <button id="relatedOrderHeaderButton" size="large" label="Customer Orders" onAction="OnAction" image="Arrow.jpg" getEnabled ="GetEnabled" tag="Action[OutlookContactCustomer.RelatedOrderHeaderAction]" /> </group> <group id="CustomerActionsGroupID" label="Customer Actions" getVisible="GetVisible" tag="Context[OutlookContactCustomer.CustomerActionsGroupID]"> <button id="SearchCustomerByPhoneButton" size="large" label="Phone Lookup" onAction="OnAction" image="MagGlass.png" getEnabled ="GetEnabled" tag="Action[OutlookContactCustomer.SearchCustomerByPhoneAction]" /> </group> </tab> </tabs> </ribbon> </customUI>
保存并关闭该文件。
打开 OIR.config 文件进行编辑。更新 OIR.config 以通过添加 RibbonFileName 属性指定要加载的功能区文件,如下例所示。
<ContextDefinitionGroup xsl:type="Declarative:DeclarativeContextDefinitionGroup" ItemType="OutlookContact" RibbonFileName="OutlookContactRibbon.xml">
为订单关联添加一个 ContextDefinitionGroup 以指定如何获取订单外部项目,如下例所示。此为可选步骤,仅在您希望在丰富列表部件中显示操作时才需要执行。
<ContextDefinitionGroup ItemType="EntityView"> <!-- The content type has to be in the format: --> <!-- length_of_entity_namespace="" length_of_entity_name="" length_of_view_name="" entity_namespace="" entity_name="" view_name="" position_of_entity_namespace="" --> <ContextDefinition ContentType="12 12 24 AWWSExample OrderHeader GetSalesOrderHeaderById 9" xsl:type="Declarative:DeclarativeContextDefinition"> <Entities> <Entity Name="OrderHeader" EntityTypeName="OrderHeader" EntityTypeNamespace="AWWSExample"> <View Name="PrimaryEntityNameInContext" ViewName="GetSalesOrderHeaderById" Description="GetSalesOrderHeaderById" IsPrimary="true" /> </Entity> </Entities> <Declarative:Layouts> <Declarative:Layout Name="Edit" LayoutFileName="EditOrderHeader"> <Declarative:Properties> <Declarative:Property Name="AssociatedActionType" Value="Edit" /> </Declarative:Properties> </Declarative:Layout> </Declarative:Layouts> <Declarative:Actions> <Declarative:CodeMethodAction MethodType="EditEntity" Name="Edit" Caption="Edit Order" DisplayLocations="ItemContextMenu" DisplayOrder="2" Scope="ItemContext" /> </Declarative:Actions> </ContextDefinition> </ContextDefinitionGroup>
更新 OIR.config 文件以为 BCS 客户端运行时提供有关所需功能区按钮和客户 ContextDefinition 的关联操作的信息。将以下代码添加到客户 ContextDefinition 中 <Declarative:Layouts> 标记的下面。
<Declarative:Actions> <Declarative:CodeMethodAction Name ="RelatedOrderHeaderAction" MethodType ="ShowTaskpaneLayout"> <Declarative:Parameters> <Declarative:ConstantParameter Name="Para1" Value="RelatedOrderHeader" ValueType="System.String"/> </Declarative:Parameters> </Declarative:CodeMethodAction> <Declarative:UrlAction Name="SearchCustomerByPhoneAction" Url="http://msn.whitepages.com/search/ReversePhone?full_phone={0}"> <Declarative:Parameters> <Declarative:ExpressionParameter Name="Para1" EntityViewInstanceReference="PrimaryEntityNameInContext" Expression="Phone"/> </Declarative:Parameters> </Declarative:UrlAction> </Declarative:Actions> <Declarative:ContextEventHandlers> <Declarative:ContextActivated ActionName="RelatedOrderHeaderAction" /> </Declarative:ContextEventHandlers>
保存并关闭该文件。
将该解决方案打包,对其进行部署和测试以确保它按照预期方式工作。
您现在已成功创建了中间声明性 Outlook 解决方案。