IsFrozen Property
Collapse the table of content
Expand the table of content

Freezable.IsFrozen Property

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

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

property bool IsFrozen {
	bool get ();
/** @property */
public boolean get_IsFrozen ()

public function get IsFrozen () : boolean

You cannot use this property in XAML.

Property Value

true if the object is frozen and cannot be modified. false if the object may be modified.

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

This property itself 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. After this point in time there is no available means to set this 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 in the nature of how any subclass of the Freezable 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 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

© 2015 Microsoft