/// <summary> /// Forces a data transfer from the binding source property to the binding target property. /// </summary> public void UpdateTarget() { if (realMode != BindingMode.OneTime && realMode != BindingMode.OneWay && realMode != BindingMode.TwoWay) { throw new ApplicationException(String.Format("Cannot update target in {0} binding mode.", realMode)); } ignoreTargetListener = true; try { Object sourceValue = sourcePropertyInfo.GetGetMethod().Invoke( source, null); if (sourceIsObservable) // work with observable list // We should take target list and initialize it using source items { IList targetListNow; if (adapter == null) { targetListNow = ( IList )targetPropertyInfo.GetGetMethod().Invoke(target, null); } else { targetListNow = ( IList )adapter.GetValue(target, targetProperty); } if (sourceValue == null) { if (null != targetListNow) { targetListNow.Clear(); } } else { if (null != targetListNow) { targetListNow.Clear(); foreach (Object x in ((IEnumerable)sourceValue)) { targetListNow.Add(x); } // Subscribe if (sourceList != null) { ((IObservableList)sourceList).ListChanged -= sourceListChanged; } sourceList = (IList)sourceValue; targetList = targetListNow; ((IObservableList)sourceList).ListChanged += sourceListChanged; } else { // Nothing to do : target list is null, ignoring sync operation } } } else // Work with usual property { Object converted = sourceValue; // Convert back if need if (null != converter) { ConversionResult result = converter.ConvertBack(sourceValue); if (!result.Success) { return; } converted = result.Value; } // if (adapter == null) { targetPropertyInfo.GetSetMethod().Invoke(target, new object[] { converted }); } else { adapter.SetValue(target, targetProperty, converted); } } } finally { ignoreTargetListener = false; } }
public ConversionResult Convert(object tFirst) { return(converter.ConvertBack(tFirst)); }