0
votes

I have created a PowerPoint VSTO Addin with a custom Task pane - and a ribbon where a toggle button defines the display / hide Status of the custom Task pane. Basis for this was the Microsoft Walkthrough information for custom Task pane and synchronizing the Ribbon with the Task pane. So fare everything works fine with the first PowerPoint window. I'm able to show the Task pane in the second and third PowerPoint window, but the toggle button on the ribbon only reacts to the last opened / created PowerPoint window and not to the Task pane displayed / hidded in the active PowerPoint window.

I've found another thread which explains exactly the same Problem here: C# VSTO-Powerpoint-TaskPanes in separate windows.

But I don't understand the answer neither I don't know how to implement a PowerPoint Inspector Wrapper.

I'm new in C# and just getting a keyword like "Inspector Wrapper" is to less for me. I already spend hours in searching the net but wasn't successfull till now.

Is there a chance to get a COMPLETE code example for PowerPoint how this works, what has to be done?

Code added: I took the code from the General walkthrough: https://msdn.microsoft.com/en-us/library/bb608590.aspx and changed it with an Event for new presentations:

The code for the ThisAddIn.cs is as follow:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

namespace PowerPointAddIn1
{
    public partial class ThisAddIn
    {
        private TaskPaneControl taskPaneControl1;
        private Microsoft.Office.Tools.CustomTaskPane taskPaneValue;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            this.Application.AfterNewPresentation += new Microsoft.Office.Interop.PowerPoint.EApplication_AfterNewPresentationEventHandler(NewPresentation);
            //taskPaneControl1 = new TaskPaneControl();
            //taskPaneValue = this.CustomTaskPanes.Add( taskPaneControl1, "MyCustomTaskPane");
            //taskPaneValue.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged);
        }

        void NewPresentation(Microsoft.Office.Interop.PowerPoint.Presentation oPres)
        {

            PowerPoint.Application app = this.Application;
            PowerPoint.DocumentWindow docWin = null;

            foreach (PowerPoint.DocumentWindow win in Globals.ThisAddIn.Application.Windows)
            {
                if (win.Presentation.Name == app.ActivePresentation.Name)
                {
                    docWin = win;
                }
            }

            this.taskPaneControl1 = new TaskPaneControl();
            this.taskPaneValue = this.CustomTaskPanes.Add(taskPaneControl1, "MyCustomTaskPane", docWin);
            this.taskPaneValue.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged);
        }

        private void taskPaneValue_VisibleChanged(object sender, System.EventArgs e)
        {
            Globals.Ribbons.ManageTaskPaneRibbon.toggleButton1.Checked =
            taskPaneValue.Visible;
        }

        public Microsoft.Office.Tools.CustomTaskPane TaskPane
        {
            get
            {
                return taskPaneValue;
            }
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}
2
Please share your code trials with usMarcel
I took the code from the General walkthrough: msdn.microsoft.com/en-us/library/bb608590.aspxRoger Heckly
Are you targeting 2007? Unless you are, the accepted answer says that the solution has to do with the CustomTaskPane collection, not InspectorWrappers.Chris
With 2013/2016 - and yes i see this but there is nowhere a complete code example which i could implement to see how it works and to be able then to adjust. Because of beginner it is very hard to understand the requirements or what has to be implemented related to the keyword custmtaskpane collection. Hope you understand my point.Roger Heckly

2 Answers

0
votes

I remember the learning curve oh so well. Here's a sample that I believe addresses your issue. You need to link the task pane to the document. I relied on the naming scheme for new documents here, but a DocumentVariable would be a much better choice (they are discarded at the end of the current session). Add a variable to the presentation, store the task pane id in the control, and compare them to get the right task pane.

You need an XML ribbon (could probably use a Ribbon Designer but those are not as good). I removed some of the boilerplate and irrelevant code from this.

ThisAddIn.cs:

namespace PowerPointAddIn1
{
    public partial class ThisAddIn
    {
        public static int counter = 0;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            this.Application.AfterNewPresentation += Application_AfterNewPresentation;
        }

        private void Application_AfterNewPresentation(PowerPoint.Presentation Pres)
        {
            int count = ++counter;

            UserControl1 uc = new UserControl1("task pane " + count);
            CustomTaskPane ctp = CustomTaskPanes.Add(uc, "custom task pane " + count);
            ctp.Visible = true;
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
        {
            return new Ribbon1();
        }
    }
}

Ribbon1.cs:

namespace PowerPointAddIn1
{
    [ComVisible(true)]
    public class Ribbon1 : Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;

        public Ribbon1()
        {
        }

        public void toggleTaskPane(Office.IRibbonControl control, bool enabled)
        {
            var CTPs = Globals.ThisAddIn.CustomTaskPanes;
            var pres = Globals.ThisAddIn.Application.ActivePresentation;

            foreach (var x in CTPs)
            {
                if (pres.Name.EndsWith(x.Title.Replace("custom task pane ", "")))
                {
                    x.Visible = enabled;
                }
            }
        }

        public bool isPressed(Office.IRibbonControl control)
        {
            var CTPs = Globals.ThisAddIn.CustomTaskPanes;
            var pres = Globals.ThisAddIn.Application.ActivePresentation;
            foreach (var x in CTPs)
            {
                if (pres.Name.EndsWith(x.Title.Replace("custom task pane ", "")))
                {
                    return x.Visible;
                }
            }
            return false;
        }
    }
}

Ribbon1.xml:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab idMso="TabAddIns">
        <group id="MyGroup"
               label="My Group">
          <checkBox id="mycheckbox" label="show task pane" onAction="toggleTaskPane" getPressed="isPressed" />
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

UsreControl1.cs (just has a label on it):

namespace PowerPointAddIn1
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1(string labelValue)
        {
            InitializeComponent();

            label1.Text = labelValue;
        }
    }
}
0
votes

I just want to share my results which works now for me (Thanks to Chris who gave me some valuable inputs). I do have a customtaskpane management which works for each presentation. The only Thing which is not yet implemented is if a user opens the document in a separate window (View / New Window). This one I don't know how to manage. As fare as I can test it this works now. here is the link to the whole solution: https://happypc-my.sharepoint.com/personal/roger_heckly_happy-pc_ch/_layouts/15/guestaccess.aspx?docid=0426d40dc5df74d66ba42a3b928111ce8&authkey=Aa6yX6QWUnqXp1jcUfGveL8

Please be Aware - I'm beginner - so if you have feedback / inputs please let me know. For sure, some code could be written easier etc.