开发者

Why is my resource dictionary not updating the look and feel? Really fed up

I have 2 Resource Dictionaries Assets/Orange/Core.xaml and Assets/Grey/Core.xaml. I want to load these dynamically. The dictionary contains implicit as well as explicit styling. I have tried the standard code for changing Resource Dictionary. The code:-

 Uri uri = new Uri("/FMT.Client;component/Assets/Orange/Core.xaml", UriKind.Relative);
            StreamResourceInfo info = Application.GetResourceStream(uri);

            if (info != null)
            {
                StreamReader reader = new StreamReader(info.Stream);
                ResourceDictionary currentDict = XamlReader.Load(reader.ReadToEnd()) as ResourceDictionary;
                reader.Close();
                if (currentDict != null)
                {
                    Application.Current.Resources.MergedDictionaries.RemoveAt(Application.Current.Resources.MergedDictionaries.Count - 1);
                    Application.Current.Resources.MergedDictionaries.Add(currentDict);

                }
            }

I don't know why is my theme not changing. I am really fed up and feel like banging my head against wall. First I put this code on specific page. But it didn't work out as expected. Then I read on some thread that this is yet another SL4's limitation and we need to put the code before page load. Reading this I put this code in App.xaml.cs in constructor just after the line InitializeComponent() and still it doesn't work. What more can I do? I have spent nearly 3 hours behind this silly useless issue. Now I can't bear it. The line Application.Current.Resources.MergedDictionaries.Add(currentDict); does get execut开发者_JS百科ed but no change in theme is seen.


It looks like you might need to clear your ResourceDictionary first but I'm not positive. However, I did find a website that modeled how to do this. Let me know if this works:

http://silverlightips.net/tag/runtime-resourcedictionary/


The original code may be properly clearing the merged dictionaries – assuming there is only 1 dictionary merged. I can’t tell from the code fragment.

BiggsTRC provided you with an excellent example.

I believe the piece of the puzzle you are missing is that you need to reset all of your static resources. Removing the older merged dictionary and adding in a new one does not update the StaticResource declarations. Notice the sample’s ResetStyles method. You probably need something like that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜