Auto formatting the XAML

Update:

Recently, I came across a new Visual Studio 2010 Extension for formatting the XAML -

"XAML Markup Styler" is a xaml beautifer, which makes XAML markup source code beautify much easier by sorting the attributes based on their importance.

This tool can help you/your team maintain a better XAML coding style as well as a much better XAML readability.

http://xamlstyler.codeplex.com/

Original Post:

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

# re: Auto formatting the XAML

Sunday, July 3, 2011 8:05 PM by ares

good

# re: Auto formatting the XAML

Wednesday, October 10, 2012 4:28 PM by ShloEmi

Thanks a lot!!

Leave a Comment

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