I've done something recently in VS2010 using a macro that shows and hides the Tools panel when switching back and forth from code to design view in asp.net MVC3 views. It could be easily adapted to do the same for your situation I think.
This goes in the EnvironmentEvents
class file in in the VS Macro IDE after the pre-generated content.
<System.ContextStaticAttribute()> Public WithEvents CommandEvents As EnvDTE.CommandEvents
Public Sub DTEEvents_OnMacrosRuntimeReset() Handles _
DTEEvents.OnMacrosRuntimeReset
CommandEvents = DTE.Events.CommandEvents
End Sub
Private Sub DTEEvents_OnStartupComplete() Handles _
DTEEvents.OnStartupComplete
CommandEvents = DTE.Events.CommandEvents
End Sub
Public Sub CommandEvents_AfterExecute( _
ByVal Guid As String, _
ByVal ID As Integer, _
ByVal CustomIn As Object, _
ByVal CustomOut As Object) _
Handles CommandEvents.AfterExecute
If DTE.Commands.Item(Guid, ID).Name = "View.ViewDesigner" Then
DTE.ExecuteCommand("View.Toolbox")
End If
If DTE.Commands.Item(Guid, ID).Name = "View.ViewMarkup" Then
DTE.Windows.Item(Constants.vsWindowKindToolbox).Close()
End If
End Sub
It could probably be better optimized using the guids of the event rather than the if statements. It works when you use the hot keys for switching views as well as the view menu, but not the context menu.