Silverlight動態載入呼叫XAML資源

yubinfeng發表於2014-04-28
 

     以多語言為例子:

    ResourceDictionary resourceDictionary = new ResourceDictionary(); //新建資源集合

            var culture = CultureInfo.CurrentCulture;//獲取本地Culture

            if (culture.Name != "zh-CN")

            {

                Application.LoadComponent(resourceDictionary, new Uri("/ETiger_MarketTrack;component/Language/Chinese.xaml", UriKind.Relative));

            }

            else

            {

                Application.LoadComponent(resourceDictionary, new Uri("/ETiger_MarketTrack;component/Language/English.xaml", UriKind.Relative));

            }

    //將資源集合新增到AppResource中,注意這些程式碼必須在使用這些資源的控制元件初始化之前

            Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);

相關文章