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?
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With