Why is this MergedDictionary entry causing an exception?

126 Views Asked by At

We have a control library which we reference in our main application. In it, we decided to split up our Generic.xaml into type-specific resources such as Brushes.xaml, Colors.xaml, etc., then we'd simply merge them into Generic.xaml. We created them as siblings to Generic.xaml in the Themes directory and we understood you're supposed to reference them locally relatively, like so...

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>

And here's the attributes in the Class Library's AssemblyInfo.cs

[assembly:ThemeInfo(
    // Where theme specific resource dictionaries are located
    // (used if a resource is not found in the page, or application resource dictionaries)
    ResourceDictionaryLocation.None,

    // Where the generic resource dictionary is located
    // (used if a resource is not found in the page, app, or any theme specific resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly
)]

...but it throws the following exception...

{"Cannot locate resource 'brushes.xaml'."}

(Note the exception is lower-case too. Odd.)

Now I've tried "Brushes.xaml", "Themes/Brushes.xaml" and "/Themes/Brushes.xaml" but to no avail. What the heck am I missing?

Note: It seems to work if the resources are in the same assembly as the application. This seems to be only relative to separating the resources out into a class library.

1

There are 1 best solutions below

0
On

Found it. Generic.xaml has special rules where you have to use the fully-qualified source. This worked...

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/ControlLibrary;component/Themes/Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>