using GalaSoft.MvvmLight.Ioc; using MuchInfo.Chart.App.Services; using MuchInfo.Chart.Data.EnumTypes; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Data; namespace MuchInfo.Chart.App.Converters { [ValueConversion(typeof(KeyValuePair), typeof(ChartLanguageType))] public class LanguageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var dataService = SimpleIoc.Default.GetInstance(); var list = dataService.GetLanguages(); if (value == null) return list.FirstOrDefault(); var type = (ChartLanguageType)value; IndexFormula.Finance.Win.SetLanguage.SetcurrentLanguage((ChartLanguageType)value); return list.FirstOrDefault(z => z.Key == type); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var keyPair = (KeyValuePair)value; return keyPair.Key; } } }