Adding a custom contextual group to the SharePoint Rbbon

Back to Walkthrough

This topic describes how to add a custom contextual group to the SharePoint Rbbon.

Defining the contextual webpart

To use contextual group create webpart derived from QASPRibbon.ContextualWebPart class:
using System.ComponentModel;
using QASPRibbon;
using QASPRibbon.Controls;

namespace QASPRibbonDemo.ContextualDemoWebPart
{
    [ToolboxItemAttribute(false)]
    public class ContextualDemoWebPart : ContextualWebPart
    {
        public override RibbonContextualGroup GetContextualGroupDefinition()
        {
            //TODO: define custom RibbonContextualGroup
            return null;
        }
    }
}

Defining the custom contextual group

Modify GetContextualGroupDefinition method:
public override RibbonContextualGroup GetContextualGroupDefinition()
{
    // ContextualGroup
    var contextualGroup = new RibbonContextualGroup("GroupId", "GroupTitle")
        {
            Color = RibbonContextualColor.LightBlue
        };
    // Tab
    var tab = new RibbonTab("TabId", "TabTitle");

    // Group            
    var group = new RibbonGroup("GroupId", "GroupTitle");
            
    // Section
    var section = new RibbonGroupSection
        {
            Type = RibbonSectionType.OneRow,
            DisplayMode = RibbonDisplayMode.Image32AndCaption 
        };

    // Button
    var button = new RibbonButton("ButtonId", "ButtonTitle")
        {
            Image = RibbonImageDefinition.Standard15(2, 5),
            OnClientClick = "alert('ButtonId has been clicked!');"
        };

    // Adding button to the section
    section.Controls = new RibbonControl[] {button};

    // Adding group to the section
    group.Sections = new RibbonGroupSection[] {section};

    // Adding group to the tab
    tab.Groups = new RibbonGroup[] {group};

    // Adding tab to the contextual group
    contextualGroup.Tabs = new RibbonTab[] {tab};

    return contextualGroup;
}

Color of contextual group can be set by using Color property.

Deploying

Deploy solution and add webpart to the page.

Result

Custom contextual group:

See also

Walkthrough

Adding a custon tab to the SharePoint Rbbon

Documentation

RibbonContextualGroup
RibbonTab
RibbonGroup
RibbonGroupSection

Contextual group' colors

Last edited Aug 25, 2013 at 12:11 PM by VitalyZhukov, version 11

Comments

No comments yet.