.netwpfxamlcode-readability

How to order WPF tag attributes consistently


While working with WPF I switch between XAML and the designer. This causes the attributes on each element to be ordered differently and makes the code harder to read unless I go though and reorder everything manually.

Is there an easier way to do this?

<TextBox Name="txtFirstName" Text="{Binding Path=FirstName, Mode=Default}" Grid.Column="1" Margin="6,2,31,11" Grid.Row="5" />

<TextBox Grid.RowSpan="2" Text="{Binding Path=LastName, Mode=Default}" Margin="6,0,31,4" Name="txtLastName" Grid.Column="1" Height="25" Grid.Row="3" VerticalAlignment="Bottom" />

Solution

  • I use the XAML Styler extension to format my XAML files. It automatically sorts attributes by a configurable priority and does some other nice formatting for you.

    enter image description here