Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellisense with Resource Dictionary in separate Assembly

I have a solution in vs2015 with two assemblies. One of them is a WPF application and the other is a WPF Class Library.

In My class library project root I have one ResourceDictionary called Directory.xaml - This has some styles, a few brushes and some strings etc.

Using:

<ResourceDictionary Source="pack://application:,,,/Resources;component/Directory.xaml"/>

I can successfully use the resources, however I intend to use the compiled class library (dll) in future projects, the issue is, unless I import the project and reference that instead of just referencing the dll, I don't have any intellisense support.

Any ideas?

like image 827
JLangford Avatar asked Jan 13 '16 14:01

JLangford


1 Answers

I hope someone comes up with a better answer, but a workaround I decided upon was to use a class in the Library dll with the keys defined as const strings, using those defined strings in the dictionary, and then using the defined strings in the Application, where I get intellisense on the keys.

In the library dll, create a class that will have the resource keys defined:

public class KeyDefinitions {
  public const string Key1 = "key1";
  public const string Key2 = "key2";
}

Also in the library dll, in the resource dictionary, use those keys (sadly, I did not get Intellisense in the library's resource xaml file to detect members of KeyDefinitions):

<BitmapImage x:Key="{x:Static local:KeyDefinitions.Key1}" UriSource="../Images/Img1.bmp"/>
<BitmapImage x:Key="{x:Static local:KeyDefinitions.Key2}" UriSource="../Images/Img2.bmp"/>

Then, in the Application, in the xaml, you can reference the keys from the KeyDefinitions class and get intellisense and compile-time checking on the keys:

<Image Source="{DynamicResource ResourceKey={x:Static myLibraryNamespace:KeyDefinitions.Key1}}" />
<Image Source="{DynamicResource ResourceKey={x:Static myLibraryNamespace:KeyDefinitions.Key2}}" />

Of course, this assumes you have control over the Library dll!

like image 137
Jeremy Avatar answered Sep 19 '22 06:09

Jeremy