Quick Timesaver When Coding Xaml

Try this in your Xaml…

<Button
VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="5"
Height="30" />


If Intellisense is doing its job, your actual key-strokes were

<Bu  <tab>
ve <tab> c <tab>
ho <tab> c <tab>
ma <tab> 5 <hunt for right arrow, hit arrow, fingers back on keyboard>
he <tab> 30 <repeat hunt for right arrow>

I get why Intellisense can’t figure out when to move me to the right of the double quotes for the margin and the height, but I hate looking for the right arrow.KeyboardMapping

Today, with a little help from a friend, I fixed that by opening Tools->Options->Environment

->Keyboard and entering the letters lineend into the search box.

Click on Edit.LineEnd, type Control-semicolon into the Shortcut keys entry box, and press the button Assign.

Presto! control-semicolon is now a synonym for “go to the end of the line” and I’ve cut the time it takes to fill in values in Xaml significantly.

About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET will be released early in 2025. Liberty is a Senior SW Engineer for CNH and he was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Microsoft MVP.
This entry was posted in Essentials, Patterns & Skills and tagged . Bookmark the permalink.

7 Responses to Quick Timesaver When Coding Xaml

  1. Carsten says:

    Personally I do not understand why IntelliSense can’t figure it out. In your case, a TAB in the string for a number is garbage. Indeed the XAML parser throws a XamlParseException. The same goes for a CR (I use the Enter key instead of the Tab key for completion).
    To me Microsoft should put intelligence into IntelliSense. It should know that the type of Height is int. Hence any character outside 0-9 should terminate entering the property and move the cursor beyond the double quote. I will settle for TAB or CR mean move the cursor beyond the double quote. Force users to use something like Ctrl+TAB and Ctrl+CR if the really need TAB and CR in a literal string. I don’t think I have had the need for the latter.

  2. Peter Brady says:

    I’ve taken to using Ctrl-U (which makes the next letter lowercased). It advances the cursor one position, and since the quotation mark doesn’t have a lowercase equivalent, the text is not affected.

  3. @Crwth
    I too would be happier with an intelligent close-quote but faililng that….

    And yes, the reason for all of this is to keep my fingers on the home row. It is too big a stretch for me to get to the arrow or the end key, even on a regular keyboard.

    And yes, this only works when entering, not editing code, but I don’t see a command I can grab that would work with editing.

  4. paul says:

    Isn’t there an “End” key?

  5. Erno says:

    Also, this Edit.LineEnd will only work when entering code, not when editing code unless you have a single attribute on a single line. If not Edit.LineEnd will jump too far to the right. Ctrl+right arrow is fine for me .

  6. Grateful Developer says:

    THANK YOU !!! The whole right-arrow thing has driven me nuts. This is awesome.

  7. Crwth says:

    Am I right in guessing you’re using a laptop, making the right-arrow hard to find? Or is it leaving your home-row that you’re trying to avoid?

    I’d be happier if typing the close-quote in XAML intelligently lept over the existing one, much as it does when you write

    if (foo==”bar”<–

    in the code-behind.

Comments are closed.