Reputation: 1171
I am developing a user control and use it inside an ElementHost. I define the resource dictionary as follows:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/Classic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
In my VS explorer, I have this
Project (the user control library)
|_ Themes
|__ Generic.xaml (Build Action = Page)
|__ Classic.xaml (Build Action = Page)
There's no compilation error and the VS designer seems to pick up the resources defined in Classic.xaml
However, it crashes at runtime with the following exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Windows.Markup.XamlParseException: 'Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '16' and line position '18'. ---> System.IO.IOException: Cannot locate resource 'themes/classic.xaml'.
What's going on?
Upvotes: 4
Views: 7691
Reputation: 1171
I ended up having to use the syntax that includes the assembly name... don't ask me why
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/assemblyname;component/Themes/Classic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Upvotes: 9
Reputation: 12295
Hi try it without slash , we use slash when Build Action is Content or other but for ResourceDictionary build Action is Page.
<ResourceDictionary Source="Themes/Classic.xaml"/>
<ResourceDictionary Source="Themes/Generic.xaml"/>
I hope this will help. You must have some other names for these Resource Dictionaries because in Themes folder of the same project Generic.xaml is used as default and its resource can be accessed without mergeing it.
Upvotes: 1