views:

34

answers:

1

I am trying to use theming within my application, but I am having a problem with my styling not being applied correctly. I run the following lines of code:

        App.Current.Resources.MergedDictionaries.Clear();                       
        ResourceDictionary rd = new ResourceDictionary();
        rd.Source = new Uri( "/Style2.xaml", UriKind.RelativeOrAbsolute );
        App.Current.Resources.MergedDictionaries.Add( rd );

Do I need to refresh the page? If so, how do I do that in Silverlight?

Thanks! Blake

+1  A: 

Yes you need to "Refresh the page" static resources are as the name suggests static. The Xaml parser resolves them on the fly as it were.

You will need to create a new instance of whatever it is you currently have assigned to the App.RootVisual and re-assign it. Here is some general code that might do the trick:-

  App.RootVisual = (UIElement)Activator.CreateInstance(App.RootVisual.GetType());
AnthonyWJones
Do you know how this would work with Prism? I'm new to Prism as well, but it seems like this might interfere with the Boostrapper.
Blake Blackwell
@Blake: Sorry no I don't I have thankfully steered clear of Prism for now. However if its similar to other MVVM solutions my answer will be a problem. Can you not include in the process of invoking this theme change some sense of navigation, thus causing the loading of a new page anyway?
AnthonyWJones
Yes, that's a good idea. I want to handle the user's style at login so I can navigate and load another page at that time. Also, I'm started to look at "Implicit Styling" and it looks like that can help.
Blake Blackwell