Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

CObobox能中英文切换 绑定不了xaml资源 (.cs 文件添加的, list.Add(

你好,MainWindow.xaml
public MainWindow()

    {
        InitializeComponent();

        _currentLan = "ZH";

        List<MyCOMBOX> list = new List<MyCOMBOX>();
        list.Add(new MyCOMBOX { cbID = 0, cbName = "Default parameters" });
        list.Add(new MyCOMBOX { cbID = 1, cbName = "Monocrystalline acid-polished wafers" });
        cobChoose.ItemsSource = list;
        cobChoose.SelectedIndex = 0;
        
` //2、ResourceHelper.cs
 private static List<System.Windows.ResourceDictionary> _Resourcelist = new List<ResourceDictionary>();
 public static void LoadResource(string languageName) {var currentResourceDictionary = (from d in _Resourcelist
                                                         where d.ToString().Equals(languageName)
                                                         select d).FirstOrDefault();if (currentResourceDictionary == null){string appPath = AppDomain.CurrentDomain.BaseDirectory;
string langType = appPath + string.Format(@"/Language/{0}.xaml", languageName); // Language.zh-CN.xaml
 // App.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(langType, UriKind.RelativeOrAbsolute) });
   var resourceDic = new ResourceDictionary() { Source = new Uri(langType, UriKind.RelativeOrAbsolute) };
                            Application.Current.Resources.MergedDictionaries.Remove(resourceDic);
                            Application.Current.Resources.MergedDictionaries.Add(resourceDic);
       CultureInfo cultureInfo = new CultureInfo(languageName);
                            Thread.CurrentThread.CurrentCulture = cultureInfo;
                            Thread.CurrentThread.CurrentUICulture = cultureInfo;}`
                            
                            
  //3、zh-CN.xaml
   <s:String x:Key="windowMainTitle">Rapid Large-area Imaging</s:String>
<s:String x:Key="buttonNewTaskWindow">Offline Test</s:String>
<s:String x:Key="menuFile">File(_F)</s:String> 


 //4、en-US.xaml
 <s:String x:Key="windowMainTitle">快速设备</s:String>
<s:String x:Key="buttonNewTaskWindow">离线测试</s:String><s:String x:Key="menuFile">文件(_F)</s:String>

界面其他BUTTON,textbox控件的中英文切换都实现了。除了COMBOX:
1.这个COMBOBOX 是在.cs 文件添加的, list.Add(new MyCOMBOX { cbID = 1, cbName = "Monocrystalline acid-polished wafers" });所以实现不了动态切换。因为绑定不了xaml资源。2.要是实现直接在xaml添加COMBOBOXITEM,就可以实现;3但是我现在想.cs 文件添加的, list.Add(new MyCOMBOX { cbID = 1, cbName = "Monocrystalline acid-polished wafers" });也能实现CObobox中英文切换,有什么方法吗?多谢各位大神指教。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...