Exporter (0) Imprimer
Développer tout

Freezable, classe

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.

Espace de noms: System.Windows
Assembly : WindowsBase (dans windowsbase.dll)
Espace de noms XML :  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public abstract class Freezable : DependencyObject
public abstract class Freezable extends DependencyObject
public abstract class Freezable extends DependencyObject
Cette classe est abstraite ; consultez Hiérarchie d'héritage pour connaître les classes non abstraites dérivées qui peuvent être utilisées dans 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.
    myBrush.Freeze();
}

myButton.Background = myBrush;  

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

Davantage de 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.

Microsoft .NET Framework 3.0 est pris en charge sur Windows Vista, Microsoft Windows XP SP2 et Windows Server 2003 SP1.

.NET Framework

Prise en charge dans : 3.0

Ajouts de la communauté

AJOUTER
Afficher:
© 2014 Microsoft