How to control the visibility of the ribbon buttons on context menu?

Add-in Express™ Support Service
That's what is more important than anything else

How to control the visibility of the ribbon buttons on context menu?
 
Mark Lei




Posts: 5
Joined: 2020-08-25
I had added some ribbon buttons on the context menu of the name 'Outlook.Explorer.ContextMenuMailItem'. I want the buttons to show only when I right click mail items, however, when I right click meeting items, they showed too.
How can I control the visibility of the ribbon buttons on context menu as I selecting different type items?
Posted 04 Sep, 2020 05:30:30 Top
Dmitry Kostochko


Add-in Express team


Posts: 2865
Joined: 2004-04-05
Hi Mark,

You need to handle the PropertyChanging event of the ribbon buttons located in your context menu, please see the code sample below:

private void adxRibbonButton1_PropertyChanging(object sender, ADXRibbonPropertyChangingEventArgs e)
{
    if (e.PropertyType == ADXRibbonControlPropertyType.Visible)
    {
        e.Value = false;
                
        Outlook.Selection selection = e.Context as Outlook.Selection;
        if (selection != null && selection.Count == 1)
        {
            object objItem = selection[1];
            if (objItem != null)
                try
                {
                    if (objItem is Outlook._MailItem)
                    {
                        e.Value = true;
                    }
                }
                finally { Marshal.ReleaseComObject(objItem); }
        }
    }
}


For more information, please have a look at the "Updating Ribbon Controls at Run Time" chapter (page 145) of the Add-in Express Developer Guide.
Posted 04 Sep, 2020 09:11:43 Top
Mark Lei




Posts: 5
Joined: 2020-08-25
Thanks, it really works.
Posted 08 Sep, 2020 02:33:51 Top