WPF 中英文切換
阿新 • • 發佈:2020-12-15
void change(string resourceName) { var resourceDict = new ResourceDictionary() { Source = new Uri($"pack://application:,,,/WPF中英文切換;component/languages/{resourceName}.xaml") }; var allLanguageDicts = Application.Current.Resources.MergedDictionaries.Where(x=> x.Source.OriginalString.Contains("languages")).ToList(); if (!allLanguageDicts.Exists(x => x.Source.OriginalString.Contains(resourceName))) { Application.Current.Resources.MergedDictionaries.Add(resourceDict); }for (int i = allLanguageDicts.Count() - 1; i > 0; i--) { var dict = allLanguageDicts[i]; if (dict.Source.OriginalString != resourceDict.Source.OriginalString) { Application.Current.Resources.MergedDictionaries.Remove(dict); } } }
原始碼:https://files.cnblogs.com/files/lizhijian/20201215WPF%E4%B8%AD%E8%8B%B1%E6%96%87%E5%88%87%E6%8D%A2.zip