views:

1041

answers:

7

Visual Studio 2008's XAML editor (SP1) cannot reformat the XML into a consistent style.

Which tools can I use to get a nicely formatted XAML file? Studio integration preferred.

+1  A: 

The only tool I found is Kaxaml, which does nice formatting ("XAML Scrubber" entry in the left menu), but being a stand-alone editor doesn't quite make the cut.

David Schmitt
+2  A: 

Have you tried CTRL K, D?

FlySwat
VS 2008's XAML Editor doesn't recognize that as a chord.
David Schmitt
VS2010 done - it's actually CTRL-K,CTRL-D (Edit.FormatDocument is what it equates to)And works quite nicely at first glance
MrPurpleStreak
+2  A: 

While browsing through the options, I found that I had to set "Position each attribute on a separate line" and "Position first attribute on same line as start tag" under "Tools > Options ... > Text-Editor > XAML > Formatting > Spacing" and reset the Keyboard mappings under "Tools > Options ... > Environment > Keyboard" to "Visual C# 2005".

Now the XAML editor reformats the XAML to my taste when pressing Ctrl+E, D.

David Schmitt
+1  A: 

http://www.dimebrain.com/2008/05/automating-read.html is a nice plugin for formatting your xaml so the attributes line up underneath each other.

Brownie
That just does what the VS2008 editor can do himself, if the options are set right.
David Schmitt
+3  A: 

Here's a link that is specific to VS2008 XAML formatting but the good news is you can do it directly inside VS.

http://geekswithblogs.net/lbugnion/archive/2007/09/29/Cleaning-up-XAML-code-and-improving-parsing-time-with-Blend.aspx

thanks, I found that already. It's good enough for me!
David Schmitt
+2  A: 

Karl just released v2 of his XAML Power toys and it can reformat your xaml from VS2008! Check out the video about XAML Power Toys Accessories

http://karlshifflett.wordpress.com/2008/09/16/xaml-power-toys-v2-release-finally-code-name-hawaii/

rudigrobler
+1  A: 

Or try xaml styler hosted at http://xamlstyler.codeplex.com/ for visual studio 2010. If you ever used Kaxaml's Xaml Scrubber and you like it, then you could think of this extension is the "Xaml Scrubber" for Visual Studio.

Check http://xamlstyler.codeplex.com/ for feature highlights.

chris