Monday, May 31, 2010

Testing Code Formatting Two

Code4Blog (VS 2010)

 <Window x:Class="FirstTwitterApp.MainWindow" 
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Testing Code Formatting

Code4Blog (VS 2010)


 <Window x:Class="FirstTwitterApp.MainWindow" 
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         xmlns:vm="clr-namespace:FirstTwitterApp.ViewModels" 
         xmlns:local="clr-namespace:FirstTwitterApp"

Code Snippet plugin for Windows Live Writer


   1: <Window x:Class="FirstTwitterApp.MainWindow"
   2:         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   3:         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:         xmlns:vm="clr-namespace:FirstTwitterApp.ViewModels"
   5:         xmlns:local="clr-namespace:FirstTwitterApp"


Sunday, May 30, 2010

Readable XAML in VS 2010

Follow Up.  I discovered ReSharper can format XAML too.  Details at the end.


This post describes how to set up Visual Studio 2010 to format “Attribute Hide & Seek” XAML like this
image
into the one-attribute-per-line format I prefer.
image

Adding the two formatting commands to the XAML editor context menu makes reformatting easy and convenient.

First, setup VS’s XAML format per this blog post (found via stackoverflow).  Then reformat all or just the selected XAML from the Edit | Advanced submenu:
SNAGHTML7808cac
Notice that the menu commands are Format Document and Format Selection.  The word “Format” is first in both.

Adding these commands to the XAML editor context menu was more of a hassle than it should have been, IMO.  I looked for “Format Document” and “Format Selection” without success in all the Categories in the Add Command dialog.  I found the commands quickly using the searchable Options / Keyboard dialog box.  Note they are “Edit.Format*”.
SNAGHTML7871bf0

However, in the UNsearchable, UNfilterable Add Command dialog they are inconveniently listed as “Document Format” and “Selection Format”.
image

Here is my updated popup menu shown on some XAML whose top line is about 3 monitors long.  (I put Format Selection first because I think it will get used most often.)
SNAGHTML79988b6

I like the formatted XAML better.
SNAGHTML79c8618

Outlining helps too.
SNAGHTML7a045ed


ReSharper formats XAML with its (duh!) XML Formatting Style.
SNAGHTML94a731d

A keyboard shortcut to ReSharper _Silent Cleanup Code works well.
SNAGHTML94d2b92