Styles Don't Update

2019-08-07 08:59发布

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条回答
成全新的幸福
2楼-- · 2019-08-07 09:39

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());
查看更多
登录 后发表回答