mainFrame.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using Aitex.UI.Charting;
  17. using Aitex.UI.Charting.Model;
  18. using Aitex.UI.Charting.ViewModel;
  19. using DataAnalysisControl.Core;
  20. namespace Aitex.UI.Charting.View
  21. {
  22. /// <summary>
  23. /// Interaction logic for MainFrame.xaml
  24. /// </summary>
  25. public partial class MainFrame : UserControl
  26. {
  27. public MainFrame()
  28. {
  29. InitializeComponent();
  30. this.Loaded += new RoutedEventHandler(MainFrame_Loaded);
  31. this.Unloaded += new RoutedEventHandler(MainFrame_Unloaded);
  32. }
  33. void MainFrame_Loaded(object sender, RoutedEventArgs e)
  34. {
  35. CommonViewModel.Instance.Start();
  36. }
  37. void MainFrame_Unloaded(object sender, RoutedEventArgs e)
  38. {
  39. CommonViewModel.Instance.Stop();
  40. }
  41. public void UpdateCultureResource(string culture)
  42. {
  43. //string culture = language == 2 ? "zh-CN" : "en-US";
  44. //Copy all MergedDictionarys into a auxiliar list.
  45. var dictionaryList = Application.Current.Resources.MergedDictionaries.ToList();
  46. //Search for the specified culture.
  47. string requestedCulture = string.Format(@"/DataAnalysisControl;component/Resources/StringResources.{0}.xaml", culture);
  48. var resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
  49. if (resourceDictionary == null)
  50. {
  51. //If not found, select our default language.
  52. requestedCulture = "StringResources.xaml";
  53. resourceDictionary = dictionaryList.
  54. FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
  55. }
  56. //If we have the requested resource, remove it from the list and place at the end.
  57. //Then this language will be our string table to use.
  58. if (resourceDictionary != null)
  59. {
  60. Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
  61. Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
  62. }
  63. //Inform the threads of the new culture.
  64. Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
  65. Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
  66. }
  67. }
  68. }