Rocher du diamant depuis la grande anse du diamant, Le Diamant, Martinique

Fixing ReSharper inspection Results used from XAML

Nov 12, 2011

Rocher du diamant depuis la grande anse du diamant, Le Diamant, Martinique

Finishing this week sprint I decided to inspect some code using ReSharper 6.1 EAP and I started to give ReSharper a chance to help me find some of broken code.

When I started I had some of the following inspection results. It is clearly showing that some properties wasn’t identified as used in a WPF binding.

So ReSharper proposed to make the property private which for sure was not ok for me has I knew it was used.

Some time ago I started to assign some design DataContext to be able to navigate from View to my ViewModel just by pressing Go to Declaration (CTRL-B in IDEA scheme) in ReSharper.

<UserControl x:Class="skyeEditor.View.StatusBarView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:ViewModel="clr-namespace:skyeEditor.ViewModel"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance Type=ViewModel:StatusBarViewModel}">

This for sure helps ReSharper code inspection as you can see on the following screenshot

Now I can navigate from View to ViewModel, can avoid to have developer deleting properties that are sued in XAML bindings, but I can also get an idea of where a ViewModel property is used by using ReSharper Find Usage (Alt-F7). I see right away that the StatusBarView.xaml is using the property ShowActivityProgress.

So don’t forget to add the d:DataContext into your XAML !