'Is it possible to "quick refactor" the element property order within the XML code?

I am now two weeks into using UWP in my C# course. And as it stands, I am getting increasingly annoyed with the way XML element properties are ordered. See how a certain section looks:

<Button x:Name="_newJourney" Content="Begin a New Journey" Margin="0,400,0,0" VerticalAlignment="Top" Height="72" Width="442" FontSize="36" Click="_newJourney_Click" Grid.Column="1" HorizontalAlignment="Center"/>
<Button Content="Load Game(?)" Height="72" Width="442" FontSize="36" Grid.Column="1" Margin="0,0,0,0" HorizontalAlignment="Center"/>
<Button Content="Options" Height="72" Width="442" FontSize="36" Margin="0,606,0,0" VerticalAlignment="Top" Grid.Column="1" HorizontalAlignment="Center"/>
<TextBox Margin="41,324,0,0" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Height="55" Grid.Column="1" HorizontalAlignment="Left" Width="379"/>
<Button x:Name="_newJourney_Copy" Content="⟲" Margin="431,324,38,0" VerticalAlignment="Top" Height="55" FontSize="36" Click="_newJourney_Click" Grid.Column="1" HorizontalAlignment="Stretch"/>

And, I'll be honest, I am standing in front of a question, do I simply reorder the element by myself, or do I ask if there is a way to actually refactor this with a quick action? My solution is to simply start off by asking.

I have tried googling, but similar to when I started programming it is rather difficult as I am unaware of the correct terms for XML / UWP designer. I.e. I don't actually think it's called properties, I don't even know if element is a correct term, I just took it from HTML.

In general, our entire class is experiencing issues searching for UWP help, we keep getting WPF tips instead :/

So, below is how I wish I could do. It would essentially sort the element properties within the XML file. The following example does include indentations, but I believe that is primarily just to show the ordering for you. I have no hope that any technique for this would perform the indentations as I've done. The actual ordering of elements is just a suggestion, I don't care if x:Name is in the beginning or the end, as long as it is consistent.

<Button  x:Name="_newJourney"       Content="New Journey"   Width="442" Height="72" Margin="0,400,0,0"      VerticalAlignment="Top"  HorizontalAlignment="Center" FontSize="36" Click="_newJourney_Click" Grid.Column="1" />
<Button  x:Name="_loadGame"         Content="Load Game(?)"  Width="442" Height="72" Margin="0,0,0,0"        HorizontalAlignment="Center" FontSize="36"  Grid.Column="1"/>
<Button  x:Name="_options"          Content="Options"       Width="442" Height="72" Margin="0,606,0,0"      VerticalAlignment="Top"  HorizontalAlignment="Center" FontSize="36"    Grid.Column="1"/>
<TextBox x:Name="_gameSeed"         Text="TextBox"          Width="379" Height="55" Margin="41,324,0,0"     VerticalAlignment="Top"  HorizontalAlignment="Left" TextWrapping="Wrap"   Grid.Column="1"  />
<Button  x:Name="_refreshGameSeed"  Content="⟲"            Width="55"  Height="55" Margin="431,324,38,0"    VerticalAlignment="Top" HorizontalAlignment="Stretch"  FontSize="36" Click="_newJourney_Click" Grid.Column="1" />

Again, another clarification. My idea for this would be something similar to CTRL-K, CTRL-F, which will auto indent code, this even works in XML. So simply a command or option that does an auto-sorting of the elements.

I've tried to be as thorough as I can possibly be, but I do fear that I am lacking a lot of term-knowledge. So if it's unclear, try reading between the lines to see what my request is. If it's still impossible, do request a clarification.



Solution 1:[1]

If you care about the order in which the properties are set in the XAML markup, you should type the markup yourself in the text editor.

If you rely on the designer to set the properties for you, you'll typically end up with something like in your first code snippet.

And no, as far as I know, there is no way to tell Visual Studio to order the attributes for you once they have been added to the markup.

The lesson here should be learn how to write XAML and stop using the designer to write code/markup for you.

You can even disable the designer altogether if you want to. In WinUI, which is the next generation UI framework for Windows, the designer support has been dropped.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mm8