XAML Auto formatting in Visual Studio 2010
· One min read
To Auto format XAML code in a readable and organized way
- Open Visual Studio 2010
- Go to Menu: Tools->Options
- Select Text Editor |->XAML |->Formatting |->Spacing
- Set the options 1 & 2 as shown in the below image
Sample Code:
<Window x:Class="WpfApplication1.MainWindow" xmlns="[http://schemas.microsoft.com/winfx/2006/xaml/presentation"](http://schemas.microsoft.com/winfx/2006/xaml/presentation"); xmlns:x="[http://schemas.microsoft.com/winfx/2006/xaml"](http://schemas.microsoft.com/winfx/2006/xaml"); Title="MainWindow" Height="350" Width="525">
<Grid> <!--Before Auto formatting -->
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="66,52,0,0" Name="button1" VerticalAlignment="Top" Width="75" /> <!--After Auto formatting -->
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="248,68,0,0" Name="button2" VerticalAlignment="Top" Width="75" /> </Grid>
</Window>