views:

59

answers:

1

I have a desktop WPF application that loads it's resources from the web, this allows us to do different things like...add a christmas theme later on down the road around the holidays if we want. To load the Theme, I would just replace the Applications current resource dictionary with our own resource dictionary like so.

        ResourceDictionary resources = null;
        System.Net.WebClient client = new System.Net.WebClient();
        using (Stream s = client.OpenRead("http://www.mywebsite.com/MyXAMLFile.xaml"))
        {
            try
            {
                resources = (ResourceDictionary)XamlReader.Load(s);
            }
            catch
            { }
        }
        Application.Current.Resources = resources;

Well we got to the point where I wanted to kinda seperate some of the resources into different files instead of using just ONE big resource file that contained everything. I thought this would be rather simple just using merged resources. I thought a simple modification to the code above would make it work, but it turns out it doesn't. This is what I expected I would have to do.

//replace the last line
Application.Current.Resources = resources;
//with this line
Application.Current.Resources.MergedDictionaries.Add(resources);

When the application is run, it just uses the normal styles, and doesn't take into account the merged resources I added. What am I doing wrong here? How am I able to dynamically add merged resources (and multiple ones) at runtime and get them to work properly?

Thanks, Kyle

A: 

My apologies, apparently it does work. With the former method I had the default styles defined already in the App.xaml, and was using StaticResources, when I changed to use the merged dictionaries I had to use DynamicResources. I thought I wiped out the styles in the App.xaml, but since there was multiple projects in my Visual Studio solution, I deleted the styles in the wrong App.xaml file!

Damn Visual Studio for making it impossible to tell what App.xaml file you're editing if there's multiple projects in the same solution :-).

Sorry again! If I knew how to delete a question I would.

kyle