3

I want to apply color schemes in an Office VSTO Add-In using the ThemeColorScheme.Load(colorSchemeFile) but not all slides are shown with the applied color scheme. In the slide thumbnail pane the slides are all shown with the correct color scheme applied and the selected slide (when the ThemeColorScheme.Load operation is executed) will also have the correct color scheme applied but the remaining slides have an inconsistent behavior if tested with many different slides in the presentation, but even with two slides, it would always fail to render the not selected one correctly.

I've created a repo that can be cloned to reproduce the issue but the main things are:

  1. Create a power point VSTO add-in project in Visual Studio
  2. Create a user control with a button that when clicked will change the color scheme of the active presentation slides (also tried applying the color theme using the presentation.Designs[i].SlideMaster.Theme.ThemeColorScheme.Load but yielded same results
    using System;
    using System.IO;
    using System.Linq;
    using System.Windows.Forms;
    
    namespace UserControls
    {
        public partial class UserControl1 : UserControl
        {
            private readonly string[] availableColorThemes = { "Test Dark", "Test Light" };
            
            private string currentTheme;
            private Microsoft.Office.Interop.PowerPoint.Application application;
    
            public UserControl1(Microsoft.Office.Interop.PowerPoint.Application application)
            {
                InitializeComponent();
                this.application = application;
                currentTheme = "Test Light";
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                var presentation = application.ActivePresentation;
                currentTheme = availableColorThemes.Where(c => c != currentTheme).First();
                string fileName = Path.Combine(Path.GetTempPath(), "PowerPointAddIn", $"{currentTheme}.xml");
    
                for (var i = 1; i <= presentation.Slides.Count; i++)
                {
                    presentation.Slides[i].ThemeColorScheme.Load(fileName);
                }
            }
        }
    }

In the reproduction repository I linked the code is reading the color scheme files from the %localappdata%\Temp\PowerPointAddIn and the two color schemes (Test Dark, Test Light) I used are in the repository root as well as the test presentation (Test Presentation).

  1. Add the previously created user control type to the task pane
using UserControls;

namespace PowerPointAddIn2
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            UserControl1 userControl1 = new UserControl1(Application);
            Microsoft.Office.Tools.CustomTaskPane myCustomTaskPaneContainer =
                CustomTaskPanes.Add(userControl1, "My Custom Task Pane");
            myCustomTaskPaneContainer.Visible = true;
        }

        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
    }
}

  1. Debug the add-in with a presentation with at least two slides

Is this a known issue? And if so, is there another way of applying a color scheme file correctly?

Appreciate any help

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
cedsan
  • 61
  • 3

0 Answers0