views:

388

answers:

3

Using Visual Studio 2008 Team Edition, is it possible to assign a shortcut key that switches between markup and code? If not, is it possible to assign a shortcut key that goes from code to markup?

+2  A: 

The following is a macro taken from a comment by Lozza on http://www.codinghorror.com/blog/archives/000315.html. You just need to bind it to a shortcut of your choice:

Sub SwitchToMarkup()
  Dim FileName

  If (DTE.ActiveWindow.Caption().EndsWith(".cs")) Then
    ' swith from .aspx.cs to .aspx
    FileName = DTE.ActiveWindow.Document.FullName.Replace(".cs", "")
    If System.IO.File.Exists(FileName) Then
      DTE.ItemOperations.OpenFile(FileName)
    End If
  ElseIf (DTE.ActiveWindow.Caption().EndsWith(".aspx")) Then
    ' swith from .aspx to .aspx.cs
    FileName = DTE.ActiveWindow.Document.FullName.Replace(".aspx", ".aspx.cs")
    If System.IO.File.Exists(FileName) Then
      DTE.ItemOperations.OpenFile(FileName)
    End If
  ElseIf (DTE.ActiveWindow.Caption().EndsWith(".ascx")) Then
    FileName = DTE.ActiveWindow.Document.FullName.Replace(".ascx", ".ascx.cs")
    If System.IO.File.Exists(FileName) Then
      DTE.ItemOperations.OpenFile(FileName)
    End If
  End If
End Sub
Luke Bennett
A: 

Thanks to Luke Bennett - I wish I'd found that macro 2 years ago!

This will save me hours of my life every month! I was surprised that I couldn't seem to do this natively in VS2010, but the macro works perfectly so I'm happy enough.

A: 

Not sure if this is what you mean, as I don't do ASPX development myself, but don't the F7 (show code) and Shift-F7 (show designer) default key bindings switch between code and design? They do in my VS2008 (on WinForms designable items) with the largely default C# key bindings I use.

peSHIr
They switch between the designer (wysiwyg) and code view but not the markup view. I find this particularly annoying by the way.
Sandor Drieënhuizen