Iris Classon mentioned about a “hidden” feature of Visual Studio which can be used to autoformat XAML here. I think it’s a good option but it’s too simple because sometime you want to have more control on formatting option (order, indent…). In this post I introduce another hard way to do autoformatting XAML.
"XAML Styler" is a Visual Studio extension, 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.
You can get XAML Styler from here
- For Visual Studio 2013: http://visualstudiogallery.msdn.microsoft.com/3de2a3c6-def5-42c4-924d-cc13a29ff5b7
- For Visual Studio 2012: http://visualstudiogallery.msdn.microsoft.com/d6634d0e-38fb-48b6-829f-dadbc5c2fb62
You can configure XAML Styler to sort attributes in the way you want, fix whitespace between <Run/>, indent XAML markup based on Visual Studio settings and many more. And you can even format XAML without using yet another shortcut key, Ctrl + S to save file also does formatting for you. For more details on features, you can find out here.