coderushforroslyn-117323-code-style-assistance-document-formatting-xaml.md
XAML markup has a complex structure that can be difficult to understand. CodeRush can format any XAML document to improve code readability and layout.
Place the caret into a XAML document.
Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
Select Format Document from the menu.
After execution, the indentation of each tag corresponds to its folding level.
<Window x:Class="MyWpfApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map"
Height="350"
Width="525"
mc:Ignorable="d"
Title="MainWindow">
<Grid>
<Grid>
<dxm:MapControl>
<dxm:ImageLayer>
<dxm:OpenStreetMapDataProvider />
</dxm:ImageLayer>
</dxm:MapControl>
</Grid>
</Grid>
</Window>
You can configure formatting of a XAML document on the Editor | XAML | Formatting options page.
Attribute Formatting - configures in which cases and how to break apart the element attributes.
Attribute Reordering - switches Attribute Reordering on and off, and configures attribute order.
Element Formatting - configures multiple aspects of XAML element formatting.
Element Reordering - enables or disables the Grid , Canvas , and Setter sorting.
Element Spacing and Text Lines Spacing - uses Visual Studio’s Element Spacing formatting options. You can override these settings, for example, to use the CodeRush’s “Place empty lines between elements in text content” option.
Markup Extension Formatting - configures the formatting options for XAML markup extensions.
See Also