ItemContextMenuDisplay event in Outlook 2013 Preview

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

ItemContextMenuDisplay event in Outlook 2013 Preview
ItemContextMenuDisplay event does not fire in Outlook 2013 Preview 
RikardG




Posts: 95
Joined: 2009-10-19
Hi,

I have started to use Outlook 2013 Preview and the ItemContextMenuDisplay event does no longer fire. I created a very simple sample project which just displays a message box when the event fires. In Outlook 2010, the event fires as expected, but in Outlook 2013 it does NOT fire.

Is this a bug or is the event deprecated in Outlook 2013?

I have upgraded my project to run version 7.0.4023 of Add-in Express.

Regards
Posted 18 Oct, 2012 04:10:23 Top
Andrei Smolin


Add-in Express team


Posts: 15196
Joined: 2006-05-11
Hello,

Yes, you are right, in Outlook 2013 the following events do not work:
AttachmentContextMenuDisplay
ViewContextMenuDisplay
ItemContextMenuDisplay
FolderContextMenuDisplay
StoreContextMenuDisplay
ShortcutContextMenuDisplay
ContextMenuClose

All these events were marked as hidden in the Outlook 2010 Object Model:
http://msdn.microsoft.com/en-us/library/office/ee836188.aspx#OL14DevRef_ChangesSince2007

The current Outlook 2013 documentation does not contain these events either:
http://msdn.microsoft.com/en-us/library/jj236930%28v=office.15%29.aspx

But as far as I know the events were not publicly declared deprecated and not working. Office 2013 is still on the Consumer Preview stage and is still very raw in some parts. I am sure Microsoft will publish a far more stable RTM version in the coming months and we will be able re-check the issue.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 18 Oct, 2012 04:30:02 Top
RikardG




Posts: 95
Joined: 2009-10-19
OK, I understand.

I use the event for displaying/hiding custom context menu buttons depending on current item. Is there another solution for this? I may have to release my product before the Outlook 2013 RTM has been released and it would be nice to have a solution right now.

Regards
Posted 18 Oct, 2012 06:52:55 Top
Andrei Smolin


Add-in Express team


Posts: 15196
Joined: 2006-05-11
You need to handle the ADXRibbonButton.PropertyChanging event for the context menu buttons in this way:
- check if e.PropertyType returns an appropriate value (e.g. ADXRibbonControlPropertyType.Visible or ADXRibbonControlPropertyType.Enabled)
- check if e.Context returns an object of the appropriate type (I suppose you need Outlook.Selection)
- check if the item(s) in the Selection meets your requirements
- set e.Value to a required value

private void adxRibbonButton1_PropertyChanging(object sender, ADXRibbonPropertyChangingEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("### PropertyType is " + e.PropertyType.ToString());
    if (e.PropertyType == ADXRibbonControlPropertyType.Enabled)
    {
        System.Diagnostics.Debug.WriteLine("### Context is " + Microsoft.VisualBasic.Information.TypeName(e.Context));
        if (e.Context is Outlook.Selection)
        {
            Outlook.Selection selection = e.Context as Outlook.Selection;
            object item = selection[1];
            if (item is Outlook.MailItem)
            {
                Outlook._MailItem mail = item as Outlook._MailItem;
                Outlook.Attachments attachments = mail.Attachments;
                System.Diagnostics.Debug.WriteLine("### Value is " + e.Value.ToString());
                if (attachments.Count > 0) 
                    e.Value = false;
                Marshal.ReleaseComObject(attachments);
            }
            Marshal.ReleaseComObject(item);
        }
    }            
}


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 18 Oct, 2012 10:55:04 Top