4

I use ReSharper 8.2.3 Full Edition with Visual Studio Ultimate 2013 and .NET 4.5.

The background is that I have a C# WPF solution with a large number of projects. To simplify the description here, I have the following projects:

Project 1: Library with UI resources (styles, fonts etc), including a resource dictionary named ResourceLibrary.xaml.

Project 2: Main exe with some WPF user controls/views and an app.xaml. The WPF user controls do NOT refer directly to ResourceLibrary.xaml in project 1. The IntelliSense works fine and ReSharper does NOT generate any warnings (blue squiggly lines).

Project 3: Library with some WPF user controls/views. All these user controls refer to ResourceLibrary.xaml:

<UserControl.Resources>
    <ResourceDictionary Source="/<my_resource_namespace>;component/ResourceLibrary.xaml" />
</UserControl.Resources>

The IntelliSense works fine and ReSharper does NOT generate any warnings (blue squiggly lines).

The solution builds fine, IntelliSense works (finds the static resources in ResourceLibrary.xaml) and ReSharper does not generate any warnings.

However, if the above lines are removed, IntelliSense does not work and ReSharper generates the warning "Resource XXX is not found". Note that this is NOT the case with the XAML files in project 2 that also uses resources in the resource library. The solution builds fine.

I want to avoid to include the resource library in every XAML file due to performance reasons but I do want ReSharper to give me relevant warnings. Is there a workaround to this problem?

I know I can turn the "The resource XXX is not found" warnings off in the ReSharper, but that would prevent me from detecting real resource problems.

Don Pedro
  • 41
  • 2
  • 1
    You can add your `ResourceDictionary` into the `MergedDictionary` in `App.xaml` Resources instead of in every XAML file. – user2250152 Jan 12 '15 at 11:25
  • Maybe I misunderstand you, but please note that the problem occurs in projects like project 3, i.e. libraries (NOT executables) = no app.xaml file. That's why xaml files in project 2 works but NOT in project 3. – Don Pedro Jan 12 '15 at 12:40
  • Anyone who knows an answer to this? – Don Pedro Jan 16 '15 at 10:02

1 Answers1

5

You might have solved this already, but this is the solution I used for my own project.

If you add a new WPF User Control in Project 3, change it to Application (and in the code behind) and add your reference to the Resource Library from there, Resharper stops complaining.

A bit of a hack, but the code is never executed and at least you don't need to modify every single controller.

<Application x:Class="Namespace.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Remove Resharper warning about "Resource ... is not found" and allow navigation/refactoring-->
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/Namespace.Infrastructure;component/SystemStyles/Styles.xaml"></ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

anderbakk
  • 311
  • 3
  • 6