While extending SharePoint 2010/2013 Ribbon with new functionality one of the common things you do is to check whether a command should be enabled or not. Since the checking function expects you to return a value it can get tricky if your custom checking operation is asynchronous. Find out how to asynchronously check if a Ribbon command is available.
While working on one of our SharePoint 2010 WCM products recently I had to apply this concept twice: once for checking if a button should be enabled and the other time for checking if a toggle button should be on or off. Below you will find sample code from the Page Component for both scenarios.
For the purpose of this article I have created the following custom Ribbon command:
<CustomAction Id="Mavention.SharePoint.Labs.MyCustomAction" Location="CommandUI.Ribbon" Sequence="10"> <CommandUIExtension> <CommandUIDefinitions> <CommandUIDefinition Location="Ribbon.WikiPageTab.PubPageActions.Controls._children"> <ToggleButton Id="Ribbon.WikiPageTab.PubPageActions.MaventionMyCustomAction" Alt="My Custom Action" Command="Mavention.SharePoint.Labs.MyCustomAction" QueryCommand="Mavention.SharePoint.Labs.MyCustomActionQuery" LabelText="My Custom Action" Sequence="40" TemplateAlias="o2" Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="-112" Image16by16Left="-16" ToolTipTitle="My Custom Action" ToolTipDescription="My Custom Action."/> </CommandUIDefinition> </CommandUIDefinitions> </CommandUIExtension></CustomAction>
No comments:
Post a Comment