LanguageConverter.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. using GalaSoft.MvvmLight.Ioc;
  2. using MuchInfo.Chart.App.Services;
  3. using MuchInfo.Chart.Data.EnumTypes;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Windows.Data;
  8. namespace MuchInfo.Chart.App.Converters
  9. {
  10. [ValueConversion(typeof(KeyValuePair<ChartLanguageType, string>), typeof(ChartLanguageType))]
  11. public class LanguageConverter : IValueConverter
  12. {
  13. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  14. {
  15. var dataService = SimpleIoc.Default.GetInstance<IDataService>();
  16. var list = dataService.GetLanguages();
  17. if (value == null)
  18. return list.FirstOrDefault();
  19. var type = (ChartLanguageType)value;
  20. IndexFormula.Finance.Win.SetLanguage.SetcurrentLanguage((ChartLanguageType)value);
  21. return list.FirstOrDefault(z => z.Key == type);
  22. }
  23. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  24. {
  25. var keyPair = (KeyValuePair<ChartLanguageType, string>)value;
  26. return keyPair.Key;
  27. }
  28. }
  29. }