title: In a VSTO MS Word add-in, a Ribbon Toggle button clicked in one document causes it to be clicked in other running instances of MS Word
body: <p>I have developed a MS Word add-in and it has several buttons in the ribbon menu. The first button is a Toggle button and clicking it causes a task pane to load. The problem I have been experiencing is that if I have multiple instances of MS Word open and I click this toggle button in one of the instances, it automatically appears clicked in the other running instances of MS Word as well but the task pane appears to be loaded only in the instance where I had clicked the toggle button. I would like the toggle button to work independently in every instance of MS Word. I have tried several ways of doing this but haven't found a solution yet. I have experienced the same behavior for another add-in that I developed for MS PowerPoint.</p>
  
  <p>Any help in this matter will be appreciated.</p>
  
  <p>I have a ribbon designer (named rbcOfficeAddin) added to my add-in project and it has a toggle button named btnTaskPane. Below is the code:</p>
  
  <pre><code>            public partial class rbcOfficeAddin
              {
                  private void btnTaskPane_Click(object sender, RibbonControlEventArgs e)
                  {
                      if (this.btnTaskPane.Checked)
                      { this.btnTaskPane.Label = "Hide Task Pane"; }
                      else { this.btnTaskPane.Label = "Show Hide Pane"; }
                      Globals.ThisAddIn.ShowHideActionPane(this.btnTaskPane.Checked);
                  }
              }
  </code></pre>
  
  <p>The click handler of toggle button calls a method of ThisAddin as shown below:</p>
  
  <pre><code>            public partial class ThisAddIn
              {
                  private bool operationsPaneCreated = false;
  
                  public void ShowHideActionPane(bool flag)
                  {
                      try
                      {
                          if (!this.operationsPaneCreated)
                          {
                              this.CreateTaskPane();
                              this.operationsPaneCreated = true;
                          }
                          myCustomTaskPane.Visible = flag;
                      }
                      catch (Exception ex)
                      {
                          MessageBox.Show(ex.Message);
                      }
                  }
  
                  private void CreateTaskPane()
                  {
                      //OperationsPane is a user control
                      oOperationsPane = new OperationsPane();
                      myCustomTaskPane = this.CustomTaskPanes.Add(oOperationsPane,
                          "Operations Pane");
  
                      myCustomTaskPane.DockPosition =
                          Office.MsoCTPDockPosition.msoCTPDockPositionFloating;
                      myCustomTaskPane.Height = 500;
                      myCustomTaskPane.Width = oOperationsPane.Width;
  
                      myCustomTaskPane.DockPosition =
                          Office.MsoCTPDockPosition.msoCTPDockPositionRight;
                      myCustomTaskPane.Width = 420;
                      myCustomTaskPane.Control.AutoScroll = true;
  
                      myCustomTaskPane.Visible = false;
  
                      myCustomTaskPane.VisibleChanged += myCustomTaskPane_VisibleChanged;
                  }
  
                  void myCustomTaskPane_VisibleChanged(object sender, EventArgs e)
                  {
                      try
                      {
                          if (!myCustomTaskPane.Visible &amp;&amp; Globals.Ribbons.rbcOfficeAddin.btnTaskPane.Checked)
                          {
                              Globals.Ribbons.rbcOfficeAddin.btnTaskPane.Checked = false;
                              Globals.Ribbons.rbcOfficeAddin.btnTaskPane.Label = "Show Task Pane";
                          }
                      }
                      catch (Exception ex)
                      {
                          MessageBox.Show(ex.Message);
                      }
                  }
              }
  </code></pre>