using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Aitex.UI.Charting; using Aitex.UI.Charting.Model; using Aitex.UI.Charting.ViewModel; using DataAnalysisControl.Core; namespace Aitex.UI.Charting.View { /// /// Interaction logic for MainFrame.xaml /// public partial class MainFrame : UserControl { public MainFrame() { InitializeComponent(); this.Loaded += new RoutedEventHandler(MainFrame_Loaded); this.Unloaded += new RoutedEventHandler(MainFrame_Unloaded); } void MainFrame_Loaded(object sender, RoutedEventArgs e) { CommonViewModel.Instance.Start(); } void MainFrame_Unloaded(object sender, RoutedEventArgs e) { CommonViewModel.Instance.Stop(); } public void UpdateCultureResource(string culture) { //string culture = language == 2 ? "zh-CN" : "en-US"; //Copy all MergedDictionarys into a auxiliar list. var dictionaryList = Application.Current.Resources.MergedDictionaries.ToList(); //Search for the specified culture. string requestedCulture = string.Format(@"/DataAnalysisControl;component/Resources/StringResources.{0}.xaml", culture); var resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture); if (resourceDictionary == null) { //If not found, select our default language. requestedCulture = "StringResources.xaml"; resourceDictionary = dictionaryList. FirstOrDefault(d => d.Source.OriginalString == requestedCulture); } //If we have the requested resource, remove it from the list and place at the end. //Then this language will be our string table to use. if (resourceDictionary != null) { Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary); Application.Current.Resources.MergedDictionaries.Add(resourceDictionary); } //Inform the threads of the new culture. Thread.CurrentThread.CurrentCulture = new CultureInfo(culture); Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture); } } }