XAML Beautifier

Format XAML layouts for WPF, MAUI, WinUI, and Avalonia.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

XAML Beautifier – Format XAML Layouts

XAML describes user interfaces in WPF, UWP, WinUI 3, .NET MAUI, Xamarin.Forms, and Avalonia. Deeply nested layouts — a Grid inside a StackPanel inside a ScrollViewer — become hard to follow when indentation is inconsistent. The XAML beautifier formats the markup so every element sits at the right depth.

What it formats

  • Panels such as Grid, StackPanel, DockPanel, and their children.
  • Property elements like <Grid.RowDefinitions> and <DataGrid.Columns>.
  • Resource dictionaries, styles, templates, and triggers.
  • Namespace declarations (xmlns:x, xmlns:local) and x:Class, x:Name attributes.

Markup extensions in attribute values — {Binding Orders}, {StaticResource AccentBrush}, {x:Static} — are left exactly as written, including their spacing and StringFormat parameters.

Indentation

Visual Studio formats XAML with 4 spaces by default, so that is the default here as well. You can switch to 2 spaces or tabs to match your .editorconfig.

Validation

XAML must be well-formed XML. Unclosed elements, duplicate attributes, or unescaped characters are reported with the line and column, which is helpful when editing XAML outside Visual Studio or Rider.

Typical uses

Clean up XAML pasted from Stack Overflow answers or documentation, normalize files generated by designers such as Blend, review UI changes in pull requests, or quickly read a layout when you are not in your IDE. Consistent indentation also makes it far easier to spot a control placed in the wrong Grid.Row or a style defined in the wrong resource dictionary, because the nesting of every element becomes visible.

Format the C# code-behind with the C# Beautifier, minify XML resources with the XML Minifier, or format other XML documents with the XML Beautifier.

Frequently Asked Questions

Yes. All XAML dialects are XML, so any well-formed XAML file is formatted regardless of the UI framework.

No. Attribute values, including {Binding ...} and {StaticResource ...} expressions, are kept exactly as written.

Not currently. Attributes stay on the element's line in their original order; only element nesting and indentation are formatted.