我有2資源詞典資產/橙/ Core.xaml和資產/灰/ Core.xaml。我想要動態加載這些。該字典包含隱式和顯式樣式。我已經嘗試了更改資源字典的標準代碼。代碼: -爲什麼我的資源字典沒有更新外觀?真的受夠了
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);
}
}
我不知道爲什麼我的主題沒有改變。我真的很厭倦,感覺好像撞在牆上。首先我把這個代碼放在特定的頁面上。但它沒有按預期工作。然後我在一些線程上看到,這是另一個SL4的限制,我們需要在頁面加載之前放置代碼。讀這個我把這個代碼放在App.xaml.cs的構造函數中,在行InitializeComponent()後面,但它仍然不起作用。我還能做什麼?我已經花了近3個小時落後於這個愚蠢的無用問題。現在我受不了了。行Application.Current.Resources.MergedDictionaries.Add(currentDict);
確實得到執行,但沒有看到主題的變化。
斷開鏈接 - 任何人都知道這個答案可能在哪裏? :) – lhan 2013-02-28 15:50:51