Skip to main content
.NET Framework Class Library
Freezable..::.CanFreeze Property

Gets a value that indicates whether the object can be made unmodifiable.

Namespace: System.Windows
Assembly: WindowsBase (in WindowsBase.dll)
Syntax
Public ReadOnly Property CanFreeze As Boolean
	Get
public bool CanFreeze { get; }
public:
property bool CanFreeze {
	bool get ();
}
member CanFreeze : bool

Property Value

Type: System..::.Boolean
true if the current object can be made unmodifiable or is already unmodifiable; otherwise, false.
Remarks

Notes to Inheritors

This method implementation uses the FreezeCore method with isChecking set to true to determine whether a Freezable can be made unmodifiable. To modify the way this property behaves in a derived class, override the FreezeCore method.

Examples

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.


			Dim myButton As New Button()
			Dim myBrush As New SolidColorBrush(Colors.Yellow)

			If myBrush.CanFreeze Then
				' Makes the brush unmodifiable.
				myBrush.Freeze()
			End If

			myButton.Background = myBrush


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

if (myBrush.CanFreeze)
{
    // Makes the brush unmodifiable.
    myBrush.Freeze();
}

myButton.Background = myBrush;  

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

Version Information

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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