Freezable Class

Defines an object that has a modifiable and a read-only (frozen) state. Classes that derive from Freezable provide detailed change notification, can be made immutable, and can clone themselves.

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

public abstract class Freezable : DependencyObject
public abstract class Freezable extends DependencyObject
public abstract class Freezable extends DependencyObject
This class is abstract; see Inheritance Hierarchy for derived non-abstract classes usable in XAML.

The Freezable class provides special features that can help improve application performance when using objects that are expensive to modify or copy. Examples of Freezable objects include the following:

Deriving From Freezable

A class that derives from Freezable gains the following features:

  • Special states: a read-only (frozen) and a writable state.

  • Thread safety: a frozen Freezable can be shared across threads.

  • Detailed change notification: Unlike other DependencyObjects, Freezable object provide change notifications when sub-property values change.

  • Easy cloning: the Freezable class has already implemented several methods that produce deep clones.

For information on using and creating your own Freezable objects, see the Freezable Objects Overview.

This example shows how to make a Freezable read-only by calling its Freeze method.

You cannot freeze a Freezable object if any one of the following conditions is true about the object:

  • It has animated or data bound properties.

  • It has properties that are set by a dynamic resource. For more information about dynamic resources, see the Resources Overview.

  • It contains Freezable sub-objects that cannot be frozen.

If these conditions are false for your Freezable object and you do not intend to modify it, consider freezing it to gain performance benefits.

The following example freezes a SolidColorBrush, which is a type of Freezable object.

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

if (myBrush.CanFreeze)
    // Makes the brush unmodifiable.

myButton.Background = myBrush;  

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

More Code

How to: Obtain a Writable Copy of a Read-Only Freezable

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

How to: Determine Whether a Freezable Is Frozen

This example shows how to determine whether a Freezable object is frozen. If you try to modify a frozen Freezable object, it throws an InvalidOperationException. To avoid throwing this exception, use the IsFrozen property of the Freezable object to determine whether it is frozen.

Any public static members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

When their IsFrozen property is false, Freezable objects can be accessed only from the thread on which the were created. Attempts to access them from other threads will throw an InvalidOperationException. Invoke or BeginInvoke provide support for marshalling work to the correct thread.

When their IsFrozen property is true, Freezable objects are free-threaded. For more information, 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