Compartilhar via


Code Snippet: Custom Ribbon Manager

Applies to: SharePoint Server 2010

The following example shows the implementation of a custom ribbon manager.

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.Office.Core;
using Microsoft.Office.BusinessApplications.Runtime;
using outlookPIA = Microsoft.Office.Interop.Outlook;
using Microsoft.BusinessData.Runtime;
using Microsoft.Office.BusinessData.Offlining;
using Microsoft.BusinessData.MetadataModel;


namespace ContosoCustomer
{

    [ComVisible(true)]
    public class CustomRibbonManager : Microsoft.Office.BusinessApplications.Runtime.RibbonManager
    {

        public static outlookPIA.Application currentOutlookApplication;
        
        public override bool GetEnabled(IRibbonControl control)
        {
            //Retrive trusted Outlook Interop object. 
            if (currentOutlookApplication == null)
            {
                outlookPIA.Inspector CurrentInspector = control.Context as outlookPIA.Inspector;
                currentOutlookApplication = CurrentInspector.Application as outlookPIA.Application;
            } 
            return base.GetEnabled(control);
        }

        public override void OnAction(IRibbonControl control)
        {
            base.OnAction(control);
        }

        public override string GetCustomUI(string ribbonID)
        {
            return base.GetCustomUI(ribbonID);
        }

        public override bool GetVisible(IRibbonControl control)
        {
            return base.GetVisible(control);
        }

        public override void OnLoad(IRibbonUI ribbon)
        {
            base.OnLoad(ribbon);
        }
    }
}