I have a Silverlight class library, called MyClassLibrary.
In it, I have a user control, called MyControl.
Within the control I define user resources:
<UserControl.Resources>
<Style x:Key="ComboBoxStyle" TargetType="ComboBox">
(lots of xaml)
</Style>
</UserControl.Resources>
The control consumes the style like this:
<ComboBox Style="{ StaticResource ComboBoxStyle }"></ComboBox>
This all works perfectly, the ComboBox comes up with the right style, so I know the style is written correctly.
What I really want is to have the style be in a resource dictionary, so that it can be used by several different controls within this assembly. So I create, in the SAME assembly, a resource dictionary. I call it ResourceDictionary.xaml.
I move the Style definition from my user control to the resource dictionary.
So then the resource dictionary looks like this:
<ResourceDictionary
xmlns="etc" >
<Style x:Key="ComboBoxStyle" TargetType="ComboBox">
(lots of xaml)
</Style>
</ResourceDictionary>
The control's user resources now look like this:
<UserControl.Resources>
<ResourceDictionary
Source="/MyClassLibrary;component/ResourceDictionary.xaml" x:Name="resDict"/>
</UserControl.Resources>
And the control still consumes the style exactly the same way as before.
Now I know that it is finding the ResourceDictionary.xaml file, because I tried changing the "Source" attribute to NonExistentFile.xaml, and it complained that it couldn't find the file. It doesn't make that complaint with ResourceDictionary.xaml, so I presume it's finding it.
However, when I run the app, I get an error that "Cannot find a Resource with the Name/Key ComboBoxStyle".
What am I doing wrong? This seems so simple and it's not working.
Thanks in advance for any help you can give me.