Visual Studio 2010 XAML Editor awkward IntelliSense?

后端 未结 2 1783
误落风尘
误落风尘 2021-02-07 13:15

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

2条回答
  •  离开以前
    2021-02-07 13:43

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

    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.

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

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

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

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

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

提交回复
热议问题