BUG: CommandbarPopup.Caption changes CommandbarPopup.CommandBar.Name and viceversa.

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2010
Date: August  2012   Microsoft Visual Studio 2012

A CommandBarPopup has a Caption property and it has a CommandBar property, which returns the internal CommandBar associated to the CommandBarPopup. In turn, this CommandBar object has a Name property. These two properties (CommandBarPopup.Caption and CommandBarPopup.CommandBar.Name) are independent and serve different purposes: the Caption is shown in the user interface and the Name is used to identify the CommandBar. However, in VS 2010 and 2012 changing the Caption property changes the CommandBar.Name property and viceversa. This didn't happen in Visual Studio 2005/2008; it is a bug introduced when VS 2010 migrated from Office-based commandbars to WPF-based commandbars.

More information

Steps to reproduce the problem:

  • Create a VB.NET add-in with the code below.
  • The add-in creates a CommandbarPopup and shows the CommandbarPopup.Caption and CommandbarPopup.CommandBar.Name values after creating it, after changing the CommandbarPopup.Caption property and after changing the CommandbarPopup.CommandBar.Name values.
Language: VB.NET   Copy Code Copy Code (IE only)
Imports System
Imports Microsoft.VisualStudio.CommandBars
Imports Extensibility
Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic

Public Class Connect	
   Implements IDTExtensibility2

   Private _applicationObject As DTE2
   Private _addInInstance As AddIn
   Private _commandBarPopup1 As CommandBarPopup

   Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
      ByRef custom As Array) Implements IDTExtensibility2.OnConnection

      _applicationObject = CType(application, DTE2)
      _addInInstance = CType(addInInst, AddIn)

      Select Case connectMode

         Case ext_ConnectMode.ext_cm_Startup
            ' OnStartupComplete will be called

         Case ext_ConnectMode.ext_cm_AfterStartup

      End Select

	End Sub

   Public Sub OnDisconnection(ByVal disconnectMode As ext_DisconnectMode, ByRef custom As Array) _
      Implements IDTExtensibility2.OnDisconnection

      If _commandBarPopup1 IsNot Nothing Then
      End If

   End Sub

   Public Sub OnAddInsUpdate(ByRef custom As Array) Implements IDTExtensibility2.OnAddInsUpdate
   End Sub

   Public Sub OnStartupComplete(ByRef custom As Array) Implements IDTExtensibility2.OnStartupComplete
   End Sub
   Public Sub OnBeginShutdown(ByRef custom As Array) Implements IDTExtensibility2.OnBeginShutdown
   End Sub

   Private Sub InitializeAddIn()

      Dim commandBars As CommandBars
      Dim standardCommandBar As CommandBar

      commandBars = CType(_applicationObject.CommandBars, CommandBars)

      standardCommandBar = commandBars.Item("Standard")

      _commandBarPopup1 = CType(standardCommandBar.Controls.Add(MsoControlType.msoControlPopup), CommandBarPopup)

      MessageBox.Show("Commandbar name:" & _commandBarPopup1.CommandBar.Name & vbCrLf & "Caption: " & _commandBarPopup1.Caption)

      _commandBarPopup1.Caption = "My popup caption"
      MessageBox.Show("Commandbar name:" & _commandBarPopup1.CommandBar.Name & vbCrLf & "Caption: " & _commandBarPopup1.Caption)

      _commandBarPopup1.CommandBar.Name = "MyPopupName"
      MessageBox.Show("Commandbar name:" & _commandBarPopup1.CommandBar.Name & vbCrLf & "Caption: " & _commandBarPopup1.Caption)

   End Sub

End Class

Related articles

Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this