/// <inheritdoc/> public override object FormatOutput(TargetInfo endPoint, TargetInfo info) { //if (!info.IsDependencyObject) // throw new NotSupportedException("A Binding can only be applied to a DependencyObject!"); if (endPoint == null) { return(null); } DependencyObject obj = (DependencyObject)endPoint.TargetObject; Binding binding = new Binding(); object src = source; if ((src == null) || ((src is string) && (".".CompareTo(src) == 0))) { if (obj is FrameworkElement fe) { src = fe.DataContext; } else if (obj is FrameworkContentElement fce) { src = fce.DataContext; } if (src == null) { return(null); } //throw new ArgumentNullException("Neither a source was specified, nor it could be retrieved from the DataContext!"); } if (String.IsNullOrEmpty(path) || String.IsNullOrEmpty(path.Trim())) { return(null); } //throw new ArgumentNullException("No path was specified!"); binding.Source = src; binding.Path = new PropertyPath(path); binding.Converter = converter; binding.ConverterParameter = converterParameter; object ret; if (info.IsDependencyObject) { ret = binding.ProvideValue(new SimpleProvideValueServiceProvider(endPoint.TargetObject, endPoint.TargetProperty, endPoint.TargetPropertyType, endPoint.TargetPropertyIndex)); } else { BindingProxy proxy = new BindingProxy(); proxy.Source = binding.ProvideValue(new SimpleProvideValueServiceProvider(proxy, BindingProxy.SourceProperty, null, -1)); proxy.Target = info; ret = proxy.TargetValue; } return(ret); }
public override object FormatOutput(TargetInfo endPoint, TargetInfo info) { //if (!info.IsDependencyObject) // throw new NotSupportedException("A Binding can only be applied to a DependencyObject!"); if (endPoint == null) return null; DependencyObject obj = (DependencyObject)endPoint.TargetObject; Binding binding = new Binding(); object src = source; if ((src == null) || (".".CompareTo(src) == 0)) { if (obj is FrameworkElement) src = ((FrameworkElement)obj).DataContext; #if SILVERLIGHT #else else if (obj is FrameworkContentElement) src = ((FrameworkContentElement)obj).DataContext; #endif if (src == null) return null; //throw new ArgumentNullException("Neither a source was specified, nor it could be retrieved from the DataContext!"); } if (String.IsNullOrEmpty(path) || String.IsNullOrEmpty(path.Trim())) return null; //throw new ArgumentNullException("No path was specified!"); binding.Source = src; binding.Path = new PropertyPath(path); binding.Converter = converter; binding.ConverterParameter = converterParameter; object ret = null; if (info.IsDependencyObject) ret = binding.ProvideValue(new SimpleProvideValueServiceProvider(endPoint.TargetObject, endPoint.TargetProperty, endPoint.TargetPropertyType, endPoint.TargetPropertyIndex)); else { BindingProxy proxy = new BindingProxy(); proxy.Source = binding.ProvideValue(new SimpleProvideValueServiceProvider(proxy, BindingProxy.SourceProperty, null, -1)); proxy.Target = info; ret = proxy.TargetValue; } return ret; }