Programmatically display a previously-disabled task pane in Word 2007

Add-in Express™ Support Service
That's what is more important than anything else

Programmatically display a previously-disabled task pane in Word 2007
 
Patrick Linskey




Posts: 5
Joined: 2010-03-24
Hi,

I'm building an add-in that has a few task panes that are initially not displayed. I want to show the task panes after a ribbon button is clicked.

My code currently does the following:

bottomTaskPaneItem.Enabled = true;


This does not reliably work. After clicking on my button, the task pane is not displayed. However, if I subsequently switch to full-screen view or open another Word document, the task pane displays at that time.

Also, if I've attached a debugger to the process, and I set a breakpoint just before that line, and then simply hit 'run' after triggering the breakpoint, the task pane does reliably re-appear.

I've tried using ShowTaskPane(), to no avail -- it has no impact, regardless of whether or not I set a breakpoint.

Is there anything else I should try to get the task pane item to reliably load?

Note that hiding the item by setting Enabled to false works beautifully.

Thanks,

-Patrick
Posted 04 Sep, 2010 12:36:57 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Patrick,

Please try using the Visible property instead. Also please have a look at the HowTo page. It contains the How to develop your first COM add-in for Microsoft Office in C# sample add-in project. You can find all the required steps in the mentioned sample project.
.NET, Extended MAPI, Windows Phone & RT
Posted 06 Sep, 2010 09:51:41 Top
Patrick Linskey




Posts: 5
Joined: 2010-03-24
Hi,

Thanks for the response.

As far as I can tell, AddinExpress.WD.ADXWordTaskPanesCollectionItem does not have a property called 'Visible'. The code in the sample that you pointed me at was using an object of type AddinExpress.MSO.ADXTaskPane, which is different than what I'm working with in a couple ways.

In particular, at the point in code at which I'm currently initializing things, I only have access to an ADXWordTaskPanesCollectionItem -- at this point in the initialization lifecycle, presumably no Word windows have been created, and thus the CollectionItem's TaskPaneInstances data structure is empty. Now, I expect that I could easily defer my initialization to a little later -- I'll try that out.

Note, however, that I based my current approach on the product documentation. It might be worthwhile to update them to at least discuss the lifecycle timing issues surrounding the use of the Enabled and ShowTaskPane() APIs.

Thanks,

-Patrick
Posted 07 Sep, 2010 20:51:19 Top
Patrick Linskey




Posts: 5
Joined: 2010-03-24
Hi,

I've figured out a workaround that seems to get things working. It's ugly, but here goes:


    var timer = new Timer();
    timer.Tick += (s, ev) =>
    {
        foreach (ADXWordTaskPane pane in bottomTaskPaneItem.TaskPaneInstances)
        {
            var p = pane;
            var del = new MethodInvoker(
                () =>
                {
                    p.Visible = true;

                    // works around a bug wherein the visibility is not 
                    // reliably updated
                    if (p.Visible)
                        timer.Enabled = false;
                });
            if (pane.InvokeRequired)
            {
                pane.Invoke(del);
            }
            else
            {
                del();
            }
        }
    };
    timer.Interval = 250;
    timer.Start();


-Patrick
Posted 07 Sep, 2010 22:19:00 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Patrick,

Sorry, I was on the wrong road. I thought you use Custom task panes, not Advanced task panes.

Please have a look at the How to make an Excel task pane visible / invisible programmatically sample project. Also you may be interested in the How to interact with several Advanced Excel Task Panes in one layout position sample project.
.NET, Extended MAPI, Windows Phone & RT
Posted 08 Sep, 2010 04:24:19 Top