Search code examples
c#wpfdata-bindingclone

Binding does not have a Clone method, whats an effective way to copy it


I wish to copy a binding, this is so i can set a different source property on it without affecting the original binding. Is this just a case of setting all of the properties on the new binding to be the same as the old?


Solution

  • if you can't find a method to do this already create an exetension for Binding.

        public static class BindingExtensions
    {
        public static Binding Clone(this Binding binding)
        {
            var cloned = new Binding();
            //copy properties here
            return cloned;
        }
    }
    
    public void doWork()
    {
        Binding b= new Binding();
        Binding nb = b.Clone(); 
    }