Accessing control inside a ribbon in Outlook using VSTO - c#

i am trying to access a label in builtIn ribbon and trying to change its visibility inside a background worker. But its not working.
My Code is
Globals.Ribbons.MailReadItemRibbon.verifyLabel.Visible = true;
If anyone know what i am doing wrong. Please help.

First of all, you should't access any UI controls from secondary threads. It is allowed to make any changes to the UI on the main thread only. You may consider using the Control.Invoke method which executes a delegate on the thread that owns the control's underlying window handle.
Second, the Fluent UI (aka Ribbon UI) is a static thing from its birth. The only possible dynamism is callbacks. So, I'd recommend using callbacks with the IRibbonUI's Invalidate or InvalidateControl methods instead. Take a look at the following articles for the sample code:
Chapter 11: Creating Dynamic Ribbon Customizations (1 of 2)
Chapter 11: Creating Dynamic Ribbon Customizations (2 of 2)
For each of the callbacks the add-in implements, the responses are cached. For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in-place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached.
The Fluent UI (aka Ribbon UI) is described in depth in the following series of articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

Related

How can I add dynamic button to Office Ribbon

How can I add dynamic toggle button to Office Ribbon? Button names are dynamic, they can change, so how can I make the buttons dynamic?
All dynamism is possible for ribbon toggle buttons via callbacks. You can customize the Ribbon UI by using callback procedures in COM add-ins. For each of the callbacks that the add-in implements, the responses are cached. For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method. You can also find the InvalidateControl method helpful which invalidates the cached value for a single control on the Ribbon user interface.
The toggleButton control has the getPressed callback which allows you to specify whether the toggle button control is pressed or not. It has the following signature:
C#: bool GetPressed(IRibbonControl control)
VBA: Sub GetPressed(control As IRibbonControl, ByRef returnValue)
C++: HRESULT GetPressed([in] IRibbonControl *pControl, [out, retval] VARIANT_BOOL *pvarfPressed)
Visual Basic: Function GetPressed(control As IRibbonControl) As Boolean
Read more about the Fluent UI (aka Ribbon UI) in the following series of articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

Add a button to Outlook message ribbon

I'm totally newbie in Office Add in Development.
Started few hours ago :)
Office version: 2016
I would like to create an add-in, with a button that will allow me to synchronize my email with my custom program and "flag" it to avoid a new synchronization in the future.
For that, it would be necessary to:
add a button (it seems simple to me, but by following this link, I did not manage to see the button when debugging in Outlook)
I would like the button is present in the ribbon that appears when you open an email, and only down (it would prevent a synchronization of several emails at once) - and I can not find the name of the adequate control. There is a list of Excel files (here) but which corresponds to the one of the opening of the mail message?
perform any action when the user clicks the button - I guess that's a simple event of the button, but how can I get the opened message data and metadata (sender, to, cc, subject ...)
"flag" the email, so as to avoid a second synchronization. The ideal is to add an icon to the email in the list of emails, as is done for an email containing attachments etc ...
I know I'm asking a lot, but I'm not asking to get the job done, just to be able to steer in the right direction. So if you have tutorials, articles etc ... to help me, it would be great.
Thank you
N.B.: Copy of this question has been posted in VSTO forum here
To create a custom ribbon UI, VSTO provides two possible ways:
Walkthrough: Create a custom tab by using the Ribbon Designer
Walkthrough: Create a custom tab by using Ribbon XML
To keep a separate state for the control for each inspector window separately you need to implement ribbon callbacks and call the Invalidate or InvalidateControl methods of the IRibbonUI interface. Read more about these methods in the following articles:
OfficeTalk: Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon User Interface (Part 1 of 2)
OfficeTalk: Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon User Interface (Part 2 of 2)
The Fluent UI (aka Ribbon UI) is described in depth:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

access the Ribbon object model outside of a VSTO add-in

I am trying to access the ribbon of Microsoft office word file using C#. and trying to change its visibility inside a background worker. Please help
By design, this is not possible. An Office Ribbon can only be controlled from code running in-process in the host Office application. What's more, the Ribbon definition must be part of the "container" of the code that's should affect the Ribbon.
This was a conscious and desired design decision by Microsoft after the experiences it has with the Ribbon predecessor - the CommandBars object model.

How to customize Excel Ribbon at runtime

Is there a way to use Netoffice to customize Office/Excel Ribbon at runtime, My concern is that I am trying to make plugin-able addin that adds button to Ribbon based on available action of my plugins.
I actually created my tab using XML but I can't figure out how to add items dynamically at runtime.
Thank you for help.
As far as I know netoffice doesn't provide anything for customizing the Fluent UI. The Ribbon UI is a static thing from its birth. The only possible dynamism is callbacks. For example, you can define a dynamicMenu which provides the getContent callback (gets an XML string that contains the contents of this dynamic menu).
Read more about the Fluent UI (aka Ribbon UI) in the following series of articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
Also you may find these articles helpful:
Chapter 11: Creating Dynamic Ribbon Customizations (1 of 2)
Chapter 11: Creating Dynamic Ribbon Customizations (2 of 2)

Access Ribbon Elements Programmatically in XML Ribbon

This seems to have been asked several times on here with no real answer:
Accessing Ribbon Controls Programatically in an XML Ribbon
Office Ribbon: How to access a control when the ribbon was created using XML
If a ribbon is created using ribbon xml, as far as I can tell, there is no programmatic exposure of the components defined in that xml. The only obvious limited way to change the state of these components is to use something like an onAction, getContent, getImage event, and the IRibbonControl element offers very little for manipulating the element in question (not to mention, most of those functions only run once, when first rendered).
So I'm trying to find a way to programmatically access those xml ribbon elements.
There is no way to programmatically access Ribbon elements when using Ribbon XML. If you want to change the state of the Ribbon controls - you need to use IRibbonUI.Invalidate() to force a new rendering of the layout (potentially using properties that trigger different behaviors at rendering time via callbacks). This can be a good thing as you have more control over when drawing occurs if you are changing multiple items' state.
See related SO post on updating Ribbon UI control state.
If you want programmatic access to Ribbon elements, you should use the Ribbon Designer. However, as stated on MSDN, the designer doesn't support all customizations. Some speculate that the designer just wraps the Ribbon XML up for you under the hood.
You just have to learn the callback mechanism utilized by the Ribbon XML - there is no control tree for you to gain access to.

Categories