Alver R.
Posts: 5
Joined: 2012-01-11
|
I have another question. Your manual shows how to display a contextual tab when a page contains a web part. But this is not what I want. I want to show my tab only when the web part becomes active, not when a page is loaded. How can I do this? Any sample please? |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Alver,
Please try to use the code below. To display a contextual group you need to implement the IWebPartPageComponentProvider interface and provide information about the contextual group and tab which should be displayed when the web part gains the focus.
Also, you can download the 'ContextualGroupsExample' example http://www.add-in-express.com/files/projects_pub/sp_contextualgroupsexample.zip.
public class MyContextRibbonUIWebPart : WebPart, IWebPartPageComponentProvider
{
private const string _ascxPath = @"~/_CONTROLTEMPLATES/ContextualGroupsExample/MyContextRibbonUIWebPart/MyContextRibbonUIWebPartUserControl.ascx";
protected override void CreateChildControls()
{
Control control = Page.LoadControl(_ascxPath);
Controls.Add(control);
}
public WebPartContextualInfo WebPartContextualInfo
{
get
{
string ribbonDesignerUniquePrefix =
typeof(Features.MyContextRibbonUI.MyContextRibbonUI).FullName.Replace(".", String.Empty);
WebPartContextualInfo info = new WebPartContextualInfo();
WebPartRibbonContextualGroup contextualGroup = new WebPartRibbonContextualGroup();
WebPartRibbonTab ribbonTab = new WebPartRibbonTab();
contextualGroup.Id = "Ribbon." + ribbonDesignerUniquePrefix + "_" + "adxspRibbonContextualGroup3";
contextualGroup.Command = "Ribbon." + ribbonDesignerUniquePrefix + "_" + "adxspRibbonContextualGroup3Command";
ribbonTab.Id = "Ribbon." + ribbonDesignerUniquePrefix + "_" + "adxspRibbonTab4";
info.ContextualGroups.Add(contextualGroup);
info.Tabs.Add(ribbonTab);
info.PageComponentId = SPRibbon.GetWebPartPageComponentId(this);
return info;
}
}
protected override void OnPreRender(EventArgs e)
{
AddinExpress.SharePoint.ADXSPRibbon.ShowContextualGroup(this.Page, typeof(Features.MyContextRibbonUI.MyContextRibbonUI), "adxspRibbonContextualGroup2");
base.OnPreRender(e);
}
}
|
|
Alver R.
Posts: 5
Joined: 2012-01-11
|
Hi Sergey,
It worked, thank you! |
|