This documentation is archived and is not being maintained.

Freezable.IsFrozen Property

Gets a value that indicates whether the object is currently modifiable.

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

public bool IsFrozen { get; }
You cannot set this property in XAML.

Property Value

Type: System.Boolean
true if the object is frozen and cannot be modified; false if the object can be modified.

Attempting to modify an object when its IsFrozen property is true throws an InvalidOperationException.

This property is read-only from the object model perspective. Some of the documentation about Freezable behaviors may mention "sets IsFrozen to true" or similar language when discussing the behavior of other methods of Freezable, but this behavior is happening internally in the class instances, when methods of the instance manipulate the private variables that exist within the abstract class. To set the value of this property, you should call Freeze. This effectively is a one-time operation to change the IsFrozen property from the initial default false state to the true state. There is no available means to set the value back to false. Instead, you could change any deep copy made from the original (see the Clone method). This is by design and is how any derived class should behave when applied to the cases where the Freezable pattern is useful.

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.

The following example freezes a SolidColorBrush and then tests it by using the IsFrozen property to determine whether it is frozen.

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

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

myButton.Background = myBrush;

if (myBrush.IsFrozen) // Evaluates to true.
    // If the brush is frozen, create a clone and 
    // modify the clone.
    SolidColorBrush myBrushClone = myBrush.Clone();
    myBrushClone.Color = Colors.Red;
    myButton.Background = myBrushClone;
    // If the brush is not frozen, 
    // it can be modified directly.
    myBrush.Color = Colors.Red;

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0