且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Visual Studio 2010 XAML编辑器笨拙的IntelliSense?

更新时间:2023-02-03 14:57:13

那总是让我很烦。一种选择是创建一个简单的宏。

That's always annoyed me too. One option is to create a simple macro.


  1. 键入XAML标签并命名。 (这时,光标位于属性的引号内。)

  2. Ctrl-Shift-R 即可开始宏录制。

  3. End ,然后按 Enter 。 (现在光标位于您要的位置。)

  4. 再次按 Ctrl-Shift-R 可以停止宏录制。

  1. Type your XAML tag and name it. (At this point your cursor is inside the quotation marks of the attribute.)
  2. Press Ctrl-Shift-R to start macro recording.
  3. Press End, and then Enter. (Now your cursor is where you want it to be.)
  4. Press Ctrl-Shift-R again to stop macro recording.

如果执行上述步骤,Visual Studio将生成以下宏代码,您可以通过按 Alt-F8 来查看这些宏代码。并打开RecordingModule.TemporaryMacro:

If you follow the steps above, Visual Studio will have generated the following macro code, which you can see if you press Alt-F8 and open RecordingModule.TemporaryMacro:

DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.NewLine()

您现在可以使用 Ctrl-Shift-P 运行此宏,但目前仅是一个临时宏。您应该保存它并将其分配给键盘快捷键。

You can now run this macro with Ctrl-Shift-P, but it's only a temporary macro at this point. You should save it and assign it to a keyboard shortcut.


  1. 打开宏浏览器( Alt-F8 )。

  2. 在MyMacros下查找TemporaryMacro | RecordingModule,并将其重命名。甚至可以将其从RecordingModule中移到另一个模块中。

  3. 打开工具菜单,然后转到选项,环境,键盘。

  4. 键入在显示包含的命令下的宏名称。

  5. 选择宏并为其分配快捷键。 (我选择了 Ctrl-Enter 。)

  1. Open Macro Explorer (Alt-F8).
  2. Find TemporaryMacro under MyMacros | RecordingModule, and rename it. Maybe even move it out of RecordingModule to a different module too.
  3. Open the Tools menu and go to Options, Environment, Keyboard.
  4. Type the name of your macro under "Show commands containing".
  5. Select your macro and assign it shortcut key(s). (I chose Ctrl-Enter.)

所以现在,不要动手按 End ,然后按 Enter ,您只需按 Ctrl-Enter

So now, instead of moving your hand to press End and then Enter, you can just press Ctrl-Enter.

我也记录了另一个宏移到该行的末尾并为我键入 />,并将其附加到 Ctrl-/ 上。 VS生成的代码如下所示:

I also recorded another macro that moves to the end of the line and types " />" for me, and attached that to Ctrl-/. The code VS generates looks like this:

DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.Text = " />"
DTE.ActiveDocument.Selection.NewLine()

所有这些宏的替代方法是:关闭自动报价。打开工具菜单,然后转到选项,文本编辑器, XAML,其他。取消选中自动插入属性引号的选项。然后,它不会为您添加结尾引号,并且您不必使用箭头键 End 键(尽管您必须键入结尾当然,现在报价)。

An alternative to all these macros is to turn off the automatic quotes. Open the Tools menu and go to Options, Text Editor, XAML, Miscellaneous. Uncheck the option for auto-inserting attribute quotes. Then it won't add the ending quote for you, and you won't have to use the arrow keys or the End key (although you will have to type the ending quote now, of course).