private BindingBase GetModifiedBinding(BindingBase binding) { Binding bindingAsBinding; MultiBinding bindingAsMultiBinding; if ((bindingAsBinding = binding as Binding) != null) { if (bindingAsBinding.ElementName != null) { return(bindingAsBinding.Clone(this.FrameworkElement.FindName(bindingAsBinding.ElementName))); } else if (bindingAsBinding.RelativeSource != null) { return(bindingAsBinding.Clone(bindingAsBinding.RelativeSource.Resolve(this.FrameworkElement))); } else if (bindingAsBinding.Source != null) { return(bindingAsBinding.Clone()); } else if (this.SourceSelectorCallback != null) { return(bindingAsBinding.Clone(this.SourceSelectorCallback(this))); } else { return(bindingAsBinding.Clone(this.FrameworkElement)); } } else if ((bindingAsMultiBinding = binding as MultiBinding) != null) { var bindings = bindingAsMultiBinding.Bindings.ToList(); MultiBinding result = bindingAsMultiBinding.Clone(); result.Bindings.Clear(); result.AddBindings(bindings.Select(b => this.GetModifiedBinding(b))); return(result); } throw new NotSupportedException(String.Format("Binding type {0} not supported.", binding.GetType())); }