About the XAML Beautifier
XAML elements collect attributes quickly. A single GridViewColumn can carry a header, a width and a binding, and a Window root carries two namespace declarations before it says anything useful. Left on one line those tags scroll off the screen and every future edit produces a diff that touches the whole line. This beautifier splits any tag holding more attributes than your threshold, putting each attribute on its own line aligned under the element name, which is the layout the Visual Studio designer writes.
Attributes below the threshold stay inline, so a short <RowDefinition Height="Auto"/> is not stretched over three lines for no reason. Empty element pairs such as <Border></Border> are collapsed to a self closing tag when the option is on. Markup extensions inside braces, including {Binding}, {StaticResource} and {TemplateBinding}, are copied through untouched because their internal spacing is significant to the parser.
The default indent is four spaces, matching the .NET convention rather than the two spaces used for web markup. The status line counts the elements, how many carry an x:Name or Name, and how many markup extensions appear, which is a fast sanity check that a paste from a designer file arrived complete. Because XAML is XML, a missing angle bracket is reported with a line and column. For markup that is not XAML, the XML Pretty Print page offers the same attribute splitting, and SVG Formatter handles vector graphics.
How to use
- Paste a XAML page, window, resource dictionary or control template into the left pane.
- Set Split above to the number of attributes your team allows on one line, usually two or three.
- Leave Collapse empty tags on to turn empty element pairs into self closing tags.
- Copy the result into Visual Studio or Rider, or download it as a
.xamlfile.
Common questions
- Does it work for WinUI 3 and .NET MAUI?
- Yes. All three dialects are XML with different namespaces, and the layout rules applied here are the same for WPF, WinUI and MAUI files.
- Are bindings ever rewritten?
- No. Anything inside curly braces is treated as opaque text, so a binding path, a converter reference and their spacing survive exactly as typed.
- Why is my root element rejected?
- Only when you tick "Require a XAML root" and the markup has neither a Microsoft XAML namespace nor a capitalised root element name. Leave it unticked for fragments.
- Can I keep attributes on one line?
- Untick "One attribute per line" and the file is indented without any attribute splitting, which produces the smallest diff against an existing file.