XAML Support in ReSharper 8

With the arrival of WinRT, it has become clear that XAML is here to stay, whether you’re writing Windows Store apps, Windows Phone apps or good old WPF desktop apps. As a result, ReSharper continues its mission to help developers deal with the verbosity of XAML. The following outlines the various XAML-related features present in ReSharper 8.

Code Completion

The fundamental operation of XAML code completion has been refined to make entity creation a simple, painless process. You can now enter the name of a type (or even a camelHumps shorthand) without either having to use the opening < symbol or the namespace prefix:

ReSharper 8 XAML type completion

For styles without a target type, we now offer automatic completion so the user can pick a type from a particular namespace:

ReSharper 8 XAML setter property completion

Also, ReSharper now provides code completion in x:Shared and xml:space attributes:

ReSharper 8 xml:Shared and xml:space completion

Style Inspections and Fixes

There are plenty of new inspections and corresponding fixes in ReSharper 8. Here’s a selection of a few of them related to control styling.

In the case where a TargetType is defined on a style setter, ReSharper will detect extraneous use of type qualifiers and will offer a fix:

ReSharper 8 XAML remove type qualifier context action

A similar fix is offered in the rare case where a redundant qualifier appears before the name of a tag:

ReSharper 8 redundant property type qualifier inspection

If a setter redefines something from a style it’s based on with a new value, ReSharper shows a gutter mark that allows navigation to the base setter:

ReSharper 8 navigate to base setter gutter mark

However, if a setter redefines it with the same value, ReSharper flags it as redundant and offers to remove it completely:

ReSharper 8 redundant property setter

As soon as you apply a style explicitly to a control and then use any of the styles that have already been defined, ReSharper flags them as redundant:

ReSharper 8 redundant style inspection

ReSharper uses very rigorous analysis when looking for redundancies. For example, with the text block’s Tag defined having the value of “Some text”, ReSharper shows the following as a redundant element:

ReSharper 8 redundant property setter

ReSharper is smart enough to handle cases like the one above with its careful attention to ways in which properties are expressed, the ordering of the properties in composite objects as well as differing namespace aliases.

Extract Style Refactoring

It’s a common situation in XAML to define inline styles for several controls and then relocate them to a style definition. ReSharper makes this operation a breeze with the Extract Style refactoring. The idea is simple: move the cursor to the element to extract styles from, press Ctrl+Shift+R and choose the Extract Style option:

ReSharper 8 Extract Style refactoring

You are presented with the dialog asking you which resource to extract the properties into (you can choose an existing resource or make a new one) as well as what properties you want to extract:

ReSharper 8 Extract Style refactoring dialog

And the end result is predictable – the chosen properties get moved into a