Freezable.CloneCore Method

Makes this instance a clone (deep copy) of the specified Freezable using base (non-animated) property values.

Namespace: System.Windows
Assembly: WindowsBase (in windowsbase.dll)

virtual void CloneCore (
	Freezable^ sourceFreezable
protected void CloneCore (
	Freezable sourceFreezable
protected function CloneCore (
	sourceFreezable : Freezable
You cannot use methods in XAML.



The object to clone.

This method is called by the Clone method and should not be called directly from your code, except when calling the base implementation while overriding this method. To create a modifiable copy of the current object, call Clone instead of calling this method directly.

Notes to Implementers: If you derive from Freezable you may need to override this method. Reasons to override include the following:

  • Your subclass has data that is not exposed via dependency properties.

  • Your subclass must perform extra initialization work that cannot be accomplished by simply overriding CreateInstanceCore. For example, if your subclass implements ISupportInitialize.

Classes that store all their data in dependency properties and that don't need to perform extra initialization work do not need to override CloneCore. It is essential that all implementations call the base implementation of this method. Implementations should only perform work that is not performed by the default implementation. The default implementation makes deep copies of all writable, locally set properties, including internal expressions. If this object has data bound dependency properties, the expressions are copied but might no longer resolve. For more information about cloning data bound objects, see the Freezable Objects Overview. If this object has animated dependency properties, the base (non-animated) value of those properties is copied. Animations are not copied. Note that unset properties are not copied, nor are read-only properties. If such a property has a default value that is a frozen Freezable, that property value will remain frozen in the otherwise modifiable clone. The following list summarizes the expected behavior for this method.
  • The copy produced should contain copies of all Freezable sub-objects.

  • Unset and read-only properties are not copied.

  • Expressions are copied.

  • None of these sub-objects are frozen on creation.

  • The copy itself should not be frozen.

  • Animations should not be copied.

  • Only property base values should be copied, not current animated values.

This example shows how to use the Clone method to create a writable copy of a read-only Freezable.

After a Freezable object is marked as read-only ("frozen"), you cannot modify it. However, you can use the Clone method to create a modifiable clone of the frozen object.

The following example creates a modifiable clone of a frozen SolidColorBrush object.

Button myButton = new Button();
SolidColorBrush myBrush = new SolidColorBrush(Colors.Yellow);

// Freezing a Freezable before it provides
// performance improvements if you don't
// intend on modifying it. 
if (myBrush.CanFreeze)
    // Makes the brush unmodifiable.

myButton.Background = myBrush;  

// If you need to modify a frozen brush,
// the Clone method can be used to
// create a modifiable copy.
SolidColorBrush myBrushClone = myBrush.Clone();

// Changing myBrushClone does not change
// the color of myButton, because its
// background is still set by myBrush.
myBrushClone.Color = Colors.Red;

// Replacing myBrush with myBrushClone
// makes the button change to red.
myButton.Background = myBrushClone;

For more information about Freezable objects, see the Freezable Objects Overview.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions