wpfvisual-studioxamlvisual-studio-2022gui-designer

Avoid "newlining" while working with XAML in Visual Studio


In my XAML, I have some components where I like to avoid too many newlines, like this label:

<Label x:Name="xLabel_ActualLevelName1" Grid.Row="1" BorderBrush="Black" BorderThickness="2" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontWeight="Bold" FontSize="25" Height="50" Width="110"
       Content="{Binding ActualLevelName}"></Label>

However, when I use the XAML designer to modify the GUI (like moving some grid which has no relationship whatsoever with that label), the label becomes something like this:

<Label x:Name="xLabel_ActualLevelName1"
       Grid.Row="1"
       BorderBrush="Black"
       BorderThickness="2"
       VerticalContentAlignment="Center"
       HorizontalContentAlignment="Center"
       FontWeight="Bold"
       FontSize="25"
       Height="50"
       Width="110"
       Content="{Binding ActualLevelName}"></Label>

How can I modify my Visual Studio's configuration in order not to add all those newlines?

I'm working with Visual Studio Enterprise 2022, version 17.10.3.

Meanwhile I've adapted the "Indending" option into "None", as you can see from this screenshot from the "Tools", "Options" menu item:

enter image description here

... but nevertheless, pressing CtrlKD still creates those unnecessary newlines.


Solution

  • I believe the option is under Spacing / Attribute Spacing select the option Preserve new lines and spaces between attributes.

    enter image description here

    Personally I prefer to have attributes on separate lines as it makes it easier to read.