using System; using System.Globalization; using System.Linq; using System.Windows.Data; using Prism.Ioc; namespace Cowain.Bake.BLL.Converter { public class CavityInfoIdConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is int val) { var p = MyAppContainer.Current.Resolve().CavityInfo.Where(x => x.Id == val).FirstOrDefault(); if (null == p) { return " "; } else { return p.Name; } } return null; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value is string val) { var p = MyAppContainer.Current.Resolve().CavityInfo.Where(x => x.Name == val).FirstOrDefault(); if (null == p) { return 0; } else { return p.Id; } } return 0; } } }