Did You Know… (2) you can easily re-format your code and XAML in Visual Studio

You might begin by opening the tools menu and selecting options followed by text editor. For each language, especially JavaScript and HTML and C# pay special attention to "new lines", the format choice (including insert attribute value quotes when typing), miscellaneous (including format HTML on paste) and make sure that you also set your preferences for both XML and XAML.

If, later, you find that you have code that is not formatted according to your specification, press ctrl -E. followed by D which instructs the Visual Studio editor to impose your formatting choices on the current document. For example with the settings that I have in my copy of Visual Studio the following code

 

<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><Canvas.Resources><Storyboard x:Name="myTimer" Completed="OnTimerCompleted" Duration="00:00:01.00" /></Canvas.Resources></Canvas>

ctrl-E, D

reformat the document to

<Canvas xmlns=http://schemas.microsoft.com/client/2007
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Canvas.Resources>
         <Storyboard x:Name="myTimer"
             Completed="OnTimerCompleted"
             Duration="00:00:01.00" /> 
     </Canvas.Resources>
</Canvas>

About Jesse Liberty

Jesse Liberty is an independent consultant and programmer with three decades of experience writing and delivering software projects. He is the author of 2 dozen books and multiple Pluralsight courses, and has been a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Xamarin Certified Mobile Developer and a Xamarin MVP, Microsoft MVP and Telerik MVP.

This entry was posted in z Silverlight Archives and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *