Tronald
Tronald

Reputation: 1585

Updating an Outlook ribbon label from another form (VSTO)

I feel completely dumb for not being able to figure this out, because I know I am missing something easy. Anyway, I have a settings form that opens when a user clicks the settings button on the Outlook ribbon I have created for my Outlook add-in. In the settings form is a checkbox, and when the user checks the box, I need to change the text of a label located back on the ribbon.

I am used to WPF, so normally what I would do in this situation is invoke a dispatcher since the form is on a different thread, but the whole dispatcher thing seems to go completely out the window with VSTO. What am I missing? Solutions for Windows Forms don't seem to work either.

Here is an example of what I am trying to do. This code would be in my settings form that pops up.

private void statusCheckBox_CheckedChange(object sender, eventargs e)
{
      OutlookRibbon outlookRibbon = new outlookRibbon();
      If(statusCheckBox.checked)
      {
           outlookRibbon.statusLabel.Label = "Checkbox Checked";
      }
}

I know in the example I am creating a new instance of my ribbon, so that is why I am not seeing the label update, but I don't really know where to go from here. Any help is appreciated.

Upvotes: 1

Views: 1072

Answers (1)

Eugene Astafiev
Eugene Astafiev

Reputation: 49445

Ribbon is a static thing from its birth. You can't set properties in the direct way. Instead, you need to use callbacks for updating controls. When you need to update the state of your controls you need to call the Invalidate or InvalidateControl methods of the IRibbonUI interface to force the host application call your callbacks to grab new values. For example:

In the XML markup file:
<customUI … OnLoad=”MyAddInInitialize” …>

In the code:
Dim MyRibbon As IRibbonUI

Sub MyAddInInitialize(Ribbon As IRibbonUI) 
     Set MyRibbon = Ribbon
End Sub

Sub myFunction()
     MyRibbon.Invalidate()         ‘ Invalidates the caches of all of this add-in’s controls    
End Sub

Upvotes: 1

Related Questions