I need to create an Outlook add-in where the ribbon will work on the toolbar and ContextMenu (right click on mailitem).
At the beginning, I did these two things separately in separate projects.
In 1 project I add Ribbon (visual design). After launching it works very well.
In the 2 project I want to do contextmenu for mail. In the class ThisAddIn.cs adds:
protected override IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new OutlookAddInExtensibility();
}
And I add class OutlookAddInExtensibility.cs:
[ComVisible(true)]
public class OutlookAddInExtensibility : IRibbonExtensibility
{
public string GetCustomUI(string RibbonID)
{
return
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<customUI xmlns=""http://schemas.microsoft.com/office/2009/07/customui"">
<contextMenus>
<contextMenu idMso=""ContextMenuMailItem"">
<button
id=""MyContextMenuMailItem""
label=""My new button label""
onAction=""RibbonMenuClick""
/>
</contextMenu>
</contextMenus>
</customUI>
";
}
public void RibbonMenuClick(IRibbonControl control)
{
MessageBox.Show("Show text");
}
After launching it works very well.
Unfortunately, when I add these two things in one project - only ContectMenu works. The ribbon at the top does not show up.
Does anyone know the solution to this problem?
You need to choose a single way for customizing the UI - export the ribbon UI designed in Visual Studio to a ribbon XML file and then combine them together. Don't forget to return an appropriate markup depending on the RibbonID parameter passed to the GetCustomUI method.
There are two ways for creating a custom UI in Office applications (in VSTO):
Due to the fact that VSTO ribbon designer doesn't provide and support all ribbon features you need to export the existing UI into XML and continue dealing with it.
See How to: Export a ribbon from the Ribbon Designer to Ribbon XML for more information.
Thanks to @Eugene Astafiev's help I found a solution. Export RibbonVisualDesigner to XML. And adding code from ContextMenu to XML. Two in one:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab id="testTab" label="Test Label">
<group id="testGroup" label="test">
<button id="testButton" onAction="testAction" label="Test" size="large"
getImage ="GetCustomImage" screentip="Test Ribbon Functionality."/>
</group>
</tab>
</tabs>
</ribbon>
<contextMenus>
<contextMenu idMso="ContextMenuMailItem">
<button idMso="FontDialog" visible="false" />
<toggleButton id="MyToggle" label="My Toggle Button" />
<button id="MyButton" label="My Button" insertBeforeMso="HyperlinkInsert" onAction="GetButtonID" />
<menuSeparator id="MySeparator" />
<menu id="MySubMenu" label="My Submenu" >
<button id="MyButton2" label="Button on submenu" />
</menu>
<gallery id="galleryOne" label="My Gallery">
<item id="item1" imageMso="HappyFace" />
<item id="item2" imageMso="HappyFace" />
<item id="item3" imageMso="HappyFace" />
<item id="item4" imageMso="HappyFace" />
</gallery>
<dynamicMenu id="MyDynamicMenu" label= "My Dynamic Menu" getContent="GetMyContent" />
</contextMenu>
</contextMenus>
</customUI>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With