Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a Custom Task Pane toggle visibility whilst keeping the UI responsive?

I'm trying to add a Custom Task Pane in an Excel Add-in which is intended to work similarly to the Pivot Tables pane.

The intention is that when a Table is selected the custom pane should appear and should disappear. To do this, I've created a custom task pane:

this._taskPane = Globals.AddIn.CustomTaskPanes.Add(
    new TableTaskPane(),
    "FooPane");
this._taskPane.DockPositionRestrict
    = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;

When the table is selected the pane is made visible, and when deselected the pane is hidden:

ListObject table = AddTable(); // Creates the table and populates with data.

table.Selected += range => this._taskPane.Visible = true;
table.Deselected += range => this._taskPane.Visible = false;

This achieves the effect of showing and hiding the pane, but unfortunately generates some lag in the UI, where the cursor "bounces" between the cells as the task pane transitions between visibility states.

This seems to be because the setter of the Visible property blocks until the Task Pane completes the transition. In Excel 2013, it slides out from the side of the window, which takes around 500ms.

I can't see any way to change this behaviour - I've tried scheduling the property-setting on the STA Thread, but it causes the same blocking. I'd be happy to change the Task Pane so that it just appears immediately without the transition (like the Pivot Table pane), but I don't see anything to make that happen either.

Am I doing this incorrectly? Is there a way to fix this with direct COM or some other subtly-hidden behaviour?

like image 552
Paul Turner Avatar asked Mar 24 '14 13:03

Paul Turner


1 Answers

You should be able to set the width of the pane to zero either through the Pane API or failing that use the Windows API SetWindowPos. Then change the visibility. I don't use VSTO but know it can be done using the raw Office Pane objects.

like image 146
Neal Avatar answered Oct 01 '22 14:10

Neal