Search code examples
wpffreezable

What is the difference between Freezable.Clone() & Freezable.CloneCurrentValue() methods


The documentation says

Clone- "Creates a modifiable clone of the System.Windows.Freezable, making deep copies of the object's values. When copying the object's dependency properties, this method copies expressions (which might no longer resolve) but not animations or their current values."

CloneCurrentValue- "Creates a modifiable clone (deep copy) of the System.Windows.Freezable using its current values."

It means both do deep copy. Then what is the difference?


Solution

  • If I understand the documentation correctly, Clone also copies the binding expressions. So if a property of the object is bound, it remains bound in the copy.

    CloneCurrentValues, on the other hand, only copies the current values, as the name implies. Bindings are not kept, so the values in the copy won't be updated if the source of the binding is modified.