2

I need some help with Resource Dictionaries in WPF. I have multiple .dll's and in each dll are one or more Resource Dictionaries. The problem is I dont know the name or the location from the Resource Dictionaries in the DLL. Now Im looking for a way to add all these Resource Dictionaries in the Code Behind in my Main.xaml

Maybe something with reflection in the assembly?

ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.Source = new Uri("Dictionary1.xaml", UriKind.Relative); ResourceDictionary resourceDictionary2 = new ResourceDictionary(); resourceDictionary.Source = new Uri("Dictionary2.xaml", UriKind.Relative); resourceDictionary2.MergedDictionaries.Add(resourceDictionary); Resources.MergedDictionaries.Add(resourceDictionary2); 

But it only add 1 Resource Dictionary... Can you help me?

1
  • Yes, somehting was buggy in my project. I did a new clean project and tried different solutions and the solution from tabby worked . Thanks! Commented Jul 19, 2017 at 12:56

2 Answers 2

1

Try this:

ResourceDictionary resourceDictionary = new ResourceDictionary { Source = new Uri("Dictionary1.xaml", UriKind.Relative) }; ResourceDictionary resourceDictionary2 = new ResourceDictionary { Source = new Uri("Dictionary2.xaml", UriKind.Relative) }; Application.Current.Resources.MergedDictionaries.Add(resourceDictionary ); Application.Current.Resources.MergedDictionaries.Add(resourceDictionary2 ); 
Sign up to request clarification or add additional context in comments.

1 Comment

do you get any exception?
1

I think your logic is wrong. Try

//Load #1 ResourceDictionary ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.Source = new Uri("Dictionary1.xaml", UriKind.Relative); //Load #2 ResourceDictionary ResourceDictionary resourceDictionary2 = new ResourceDictionary(); resourceDictionary2.Source = new Uri("Dictionary2.xaml", UriKind.Relative); //Merge #1 & #2 resourceDictionary2.MergedDictionaries.Add(resourceDictionary); //Add to Resources Resources.MergedDictionaries.Add(resourceDictionary2); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.