Auto formatting the XAML

Formatting XAML manually is very painful work and if you are used to read neatly formatted markup/code then it becomes impossible to go through other developers code. To solve this problem we thought to use Dimebrain Markup Tamer to auto format code and maintain consistency/readability; but we were not satisfied with this. Recently I found that VS itself provides very good support for formatting(auto) XAML. You just need to set few settings and that's it, you can easily format your XAML by using one shortcut and moreover if you copy paste the code VS automatically formats it. To achieve this go to

Tools->Options->Text Editor->XAML->Formatting

and modify the settings as per your preference. Now you just need to press Ctrl + k, Ctrl + D(Format Document) to format the full document.

I prefer using following settings -

image 

image

One attribute I would like to talk about is “Position first attribute on same line as start tag”, I prefer not to use it, primarily because it doesn’t align all markup properly:

Formatting with “Position first attribute on same line as start tag” checked:

image

Formatting with “Position first attribute on same line as start tag” un-checked:

image

Published Thursday, February 19, 2009 4:00 PM by akjoshi
Filed under: ,

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required)