On our BindingElement class, there is a protected ctor that takes another BindingElement as its parameter. This constructor exists in order to facilitate a composable implementation of BindingElement.Clone. When writing a custom binding element, first implement a protected copy constructor as follows (note that for sealed classes this ctor should be private):
protected
MyBindingElement(
MyBindingElement
elementToBeCloned)
: base(elementToBeCloned)
{
// copy all fields from elementToBeCloned.XXX to this.XXX
}
Then you should implement your Clone() method as follows:
public override
BindingElement
Clone()
{ return new
MyBindingElement(
this
);
}
Any BindingElement in your inheritance chain (assuming it has followed this pattern) will then copy over the relevant values in its copy constructor, so that you can be assured a full Clone of your custom binding element.
Am I missing something, or shouldn’t that be
// copy all fields from elementToBeCloned.XXX to this.XXX
Indeed, a typo on my part. Thanks for the catch!