public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } var para = (string)parameter; try { icm = JsonConvert.DeserializeObject <InstrumentConfigModel>((string)value); switch (para.ToLower()) { case "name": return(SystemSettings.InstrumentsList.First(t => t.Name == this.GetValue <string>(icm, para))); case "slot": case "channel": return(this.GetValue <string>(icm, para)); default: return(null); } } catch { return(null); } }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (icm is null) { icm = new InstrumentConfigModel(); } if (value is InstrumentModel instr) { this.SetValue(icm, (string)parameter, instr.Name); } else { this.SetValue(icm, (string)parameter, value); } return(JsonConvert.SerializeObject(icm)); }