Welcome to AspAdvice Sign in | Join | Help

Visual Studio XAML Editing Tip

So I'm working in XAML in Visual Studio 2008 and it has some nice statement completion features now, like automatically quoting my attributes for me (cool!).  When there's an item it knows, like Orientation="Horizontal|Vertical" it will give me a dropdown and after selection, put the cursor after the closing double quote, as you would expect, like this (the _ represents the cursor):

<StackPanel Orientation="Vertical"_

However, if you edit a field that doesn't have a limited set of options, like Width, you don't get this behavior, so you're trapped inside of the double quotes:

<StackPanel Orientation="Vertical" Width="30_"

None of the standard keys within reach of a touch typist will get the cursor out of the quoted area, so you have to pick up your hand and go find the right arrow or end key (or if you're really inefficient, use the mouse) before continuing on with your typing.  For a fast typist like me, this gets old fast, and dramatically slows down the otherwise incredibly exciting task of hand typing XAML into a text editor.

To fix this, I've mapped shift-Space to the Next Word command in the text editor.  To do this, in Visual Studio 2008 (I think it's the same in 2005), go to Tools - Customize and click Keyboard, or go to Tools-Options-Keyboard.  The ListBox has a few hundred items in it, so it comes with a handy filter textbox with the heading "Show commands containing:".  In this textbox, enter "WordNext" and you should see four options.  Select Edit.WordNext.

In the Use new shortcut in: you can choose between Global or just limit it to Text Editor.  Then in Press shortcut keys you should press the key combination you want to use (in my case shift+Space).VSOptions

Remember to click the Assign button and you're done!

Published Monday, January 14, 2008 6:22 PM by ssmith

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Visual Studio XAML Editing Tip

Steven-

Thanks for blogging about this. The WPF Designer team is brainstorming ways to improve this in the future.

Thanks, Rob

Rob Relyea, Program Manager, WPF/Xaml Language Teams

Tuesday, January 15, 2008 3:02 PM by Rob Relyea

# re: Visual Studio XAML Editing Tip

Nice tip.

I did use Edit.CharRight instead, to be sure i'm allways just behind the double quote (which may be different with WordNext depending on what's already behind on that line).

Thanks.

Kris Goossens

Wednesday, January 16, 2008 4:27 PM by Kris Goossens

# re: Visual Studio XAML Editing Tip

I like the idea of this tip, but in practice it caused side effects due to the way I type.  I added the Shift+Space shortcut to WordNext this morning, then later in the day was getting annoyed that whenever I typed certain things my cursor was jumping down to the next line.  I particularly noticed this right after typing a { when defining a property, or a colon in a class definition.  I realized that this is because I'm often still holding down the shift button when I hit space, which was causing the cursor to jump to the next word, which happened to be on the next line.  I removed the shortcut and I'll stick to Ctrl+Right Arrow or *gasp* the mouse.  ;-)

Also, I think a better behavior would be to have the cursor jump to the right of the attribute's quotes when you type a space.  Or, if you type a quote, have that replace the quote to the right of the cursor instead of having two quotes.  Did that make sense?

Wednesday, January 16, 2008 10:00 PM by Matt Casto

# Visual Studio Shortcuts

I was doing a bunch of Silverlight last night on a new machine and once again set up my shortcut to basically

Thursday, March 27, 2008 3:50 PM by Community Blogs

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below