I have a Silverlight class library called MyClassLibrary.
In it, I have a custom MyControl control.
Inside the control, I define user resources:
<UserControl.Resources> <Style x:Key="ComboBoxStyle" TargetType="ComboBox"> (lots of xaml) </Style> </UserControl.Resources>
The control consumes this style:
<ComboBox Style="{ StaticResource ComboBoxStyle }"></ComboBox>
This all works great, ComboBox is right style, so I know the style is spelled correctly.
I really want the style to be in the resource dictionary so that it can be used by several different controls in this assembly. Therefore, I create a resource dictionary in the SAME assembly. I call it ResourceDictionary.xaml.
I am transferring a style definition from my user control to a resource dictionary.
So, the resource dictionary is as follows:
<ResourceDictionary xmlns="etc" > <Style x:Key="ComboBoxStyle" TargetType="ComboBox"> (lots of xaml) </Style> </ResourceDictionary>
User management 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 as before.
Now I know that he finds the ResourceDictionary.xaml file because I tried to change the Source attribute to NonExistentFile.xaml and he complained that he could not find the file. He does not make this complaint with ResourceDictionary.xaml, so I assume she will find it.
However, when I launch the application, I get the error message "Cannot find the resource with the name / key of ComboBoxStyle."
What am I doing wrong? It seems so simple and doesn't work.
Thanks in advance for any help you can give me.