3

使用 Visual Studio 2008 Team Edition,是否可以分配在标记和代码之间切换的快捷键?如果没有,是否可以分配一个从代码到标记的快捷键?

4

2 回答 2

4

以下是来自 Lozza 在https://blog.codinghorror.com/visual-studio-net-2003-and-2005-keyboard-shortcuts/上的评论的宏。您只需要将其绑定到您选择的快捷方式:

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
于 2008-09-23T08:40:44.820 回答
1

不确定这是否是您的意思,因为我自己不进行 ASPX 开发,但 F7(显示代码)和 Shift-F7(显示设计器)默认键绑定不会在代码和设计之间切换吗?它们在我的 VS2008(在 WinForms 可设计项目上)中使用了我使用的大部分默认 C# 键绑定。

于 2010-08-12T10:24:13.830 回答