Reputation: 817
Is there any way to force a UI refresh or redraw of a control in an outlook add-in? I am basically updating the image of a button in my ribbon. The image is generated in the server via a WebApi call which contains a count of new records a new Image. This seems to be working fine unless the outlook window is not the active/focused window.
Below snippet is executed when my add-in receives a SignalR notification from the server. The snippet calls a webapi to get the new info containing the new image for the button.
I'm not sure what I'm doing wrong, but when there are multiple screens/monitors connected and outlook is in the extended screen (not focused), it doesn't update the button with the new image although the code was already executed. The changes only reflects when I click/focus on outlook.
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(
delegate (object o, DoWorkEventArgs args)
{
var info = MyServerCallToGetNewCountAndImage();
if (SynchronizationContext.Current != null)
{
var uiContext = SynchronizationContext.Current;
uiContext.Post(b =>
{
MyInfo i = (MyInfo)b;
// Update ribbon button image.
myButton.Image = i.Image;
}, info);
}
});
bw.RunWorkerAsync();
Upvotes: 1
Views: 137
Reputation: 897
The only way I've had any success with this is to use a combination of invalidating the ribbon using IRibbonUI.Invalidate
and switching to the outlook window and back to whatever was focused before.
This should be fine for a one time update, but would obviously interfere with the application if done often.
Upvotes: 0
Reputation: 66215
You need to call IRibbonUI.Invalidate
. IRibbonUI
interface is passed to your addin when you handle the onLoad
callback of your addin ribbon.
Upvotes: 1