Export (0) Print
Expand All

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; }

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.
                myBrush.Freeze();
            }            

            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;
            }
            else
            {
                // 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.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft