Visual Studio 2010 XAML编辑器笨拙的IntelliSense? [英] Visual Studio 2010 XAML Editor awkward IntelliSense?

查看:83
本文介绍了Visual Studio 2010 XAML编辑器笨拙的IntelliSense?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio C#文本编辑器中,当需要属性时,只需键入 prop ,然后单击TWICE选项卡即可获得属性的代码段 /模板。类型和属性名称都突出显示。要在类型和属性之间进行切换时,请按Tab键,然后在完成后按Enter键,光标将跳到属性的末尾。

In Visual Studio C# text editor, when you want a property, you just type prop and then hit tab TWICE to get a "snippet"/template for a property. Both the Type and the property name are highlighted. You press tab when you want to switch between type and property, then you press Enter when you're done and your cursor will jump at the end of the property.

在WPF XAML编辑器中,按 Enter将创建一个换行符。就像您键入以下内容一样:

In the WPF XAML editor, pressing "Enter" will create a line break. Like if you type the following:

<TextBox x:

,当您从IntelliSense中选择名称属性时,它将为您提供以下内容:

and when you select the "Name" property from the IntelliSense, it will give you the following:

<TextBox x:Name="_"

_代表您当前的光标位置。

_ represents your current cursor location.

给名称取一个值,例如文本框,然后按 Enter 。此时,我希望光标像这样跳到最后:

Give the Name a value, say textbox, then press Enter. At this point, I expect my cursor to jump at the end like so:

<TextBox x:Name="textbox"_ 

但它会像这样创建换行符:

but instead it creates a line-break like so:

 <TextBox x:Name="textbox
          _"

这种行为使我很烦。我没有按 Enter ,而是按 End 键。

This behavior is annoying me. Instead of pressing Enter, I'm pressing the End key instead.

我如何获得预期的行为?

How do I get my intended behavior?

PS:我是WPF和XAML的新手。 / p>

PS: I'm new to WPF and XAML.

推荐答案

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

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).

这篇关于Visual Studio 2010 XAML编辑器笨拙的IntelliSense?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆