A XAML beautifier for deeply nested layouts
XAML files grow fast: a window holds a Grid, which holds panels, which hold controls with styles, templates and triggers. After a few merges or a paste from a designer tool, the indentation stops telling the truth. This XAML beautifier rebuilds the indentation from the actual element structure, so what looks nested is nested.
XAML is XML, so the same rules apply to WPF, UWP, WinUI 3, .NET MAUI, Xamarin.Forms and Avalonia files.
Example
<StackPanel Margin="12" Orientation="Vertical"><TextBlock Text="{Binding Title}" FontSize="18"/><Button x:Name="SaveButton" Content="Save" Command="{Binding SaveCommand}"/><!-- TODO: cancel --></StackPanel>
With a 4-space indent:
<StackPanel Margin="12" Orientation="Vertical">
<TextBlock Text="{Binding Title}" FontSize="18"/>
<Button x:Name="SaveButton" Content="Save" Command="{Binding SaveCommand}"/>
<!-- TODO: cancel -->
</StackPanel>
Markup extensions such as {Binding Title} and {StaticResource Accent} are ordinary attribute values to an XML formatter, so they are never altered. Attributes stay on the same line as their element; the tool does not split them one per line or reorder them.
XAML features you will see in the output
- Property element syntax.
<Grid.RowDefinitions>and<DataGrid.Columns>are child elements that set a property of the parent. They are indented like any other child. - The x: namespace.
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"provides language features likex:Class,x:Nameandx:Key. The default namespace selects the UI framework's controls. - Attached properties such as
Grid.Row="1"are plain attributes and stay on their element.
Errors that stop XAML from parsing
- Attributes without values.
<Button IsEnabled/>fails withboolean attribute 'IsEnabled' is not allowed. WriteIsEnabled="True". - Ampersands. Text like
Save & Exitmust be writtenSave & Exitin XAML. Inside attribute values this check is lenient here, but the XAML compiler will still reject a raw ampersand. - Mismatched tags after cut-and-paste, reported with the line and column of the unexpected closing tag.
Type errors, unknown properties and broken bindings are only detected by the XAML compiler or at run time; this tool checks the XML layer.
Beautifier or XAML Styler?
Extensions like XAML Styler in Visual Studio apply project-wide rules such as one attribute per line and attribute ordering. This page is for quick, rule-free cleanup when you are outside the IDE: a snippet from documentation, a layout from a code review, or a file on a machine without your tooling.
For C# code-behind, the C# formatter handles the other half of the view. General XML such as .csproj files works well in the XML formatter, and XML validator gives a focused error report.
Privacy
Formatting runs in your browser; your XAML is not uploaded unless you choose Load URL or Save & Share.