Источник:
http://blogs.msdn.com/b/crm/archive/...-controls.aspx
==============
Microsoft Dynamics CRM 2011 uses Ribbons (also known as Fluent UI) to provide a user interface to display the right commands at the right time. Ribbons also provide a very powerful and flexible way of extending the ribbon functionality to meet your requirements. If you are new to ribbon customization in Microsoft Dynamics CRM 2011, see the SDK documentation:
Customize the Ribbon for Microsoft Dynamics CRM.
I’m going to show you how to create dynamic Ribbon controls. You will typically use dynamic controls so that your ribbon elements can react to changes in data or context.
ComboBox,
DropDown,
FlyoutAnchor,
MRUSplitButton and
SplitButtoncontrols can contain other collections of controls. These controls can be created with static definitions at design time or they can be populated dynamically using a
JavaScriptFunction that uses a
Script Web Resource.
In this article I will demonstrate how to dynamically create ribbon
Button elements and populate them inside a
FlyoutAnchor. The end result will look like this:
The procedure uses these steps:
- Define the Parent Control
- Define CommandDefinitions
- Create a Script Web Resource
Define the Parent Control
Once you determine the location where you would like to create a dynamic menu, create a
CustomAction to add the
CommandUIDefinition as shown below.
Important:
For both
CommandDefinition elements, you must use the
CrmParameter with the
Value attribute set to "CommandProperties". This object will be used later in the script web resources to read which dynamically generated button is selected and to set the dynamically generated ribbon xml.
Create a Script Web Resource
Create a Script Web resource named
new_dynamicmenupopulator.js. Set the contents of this JScript library to the following code:
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:7e54dcd0-6a37-4be0-bd60-b36a96a22e18" class="wlWriterSmartContent">
function DynamicMenu(CommandProperties) { var menuXml =''; CommandProperties.PopulationXML = menuXml; } function Search(CommandProperties) { var controlId = CommandProperties.SourceControlId; switch (controlId) { case'ISV.Dynamic.Button1': alert('Button 1 Command Implementation'); break; case'ISV.Dynamic.Button2': alert('Button 2 Command Implementation'); break; default: alert('Button Unknown'); } }