Google News
logo
WPF - Interview Questions
Explain freezable objects in WPF.
Freezable objects are special types of objects with two states i.e., unfrozen and frozen. Objects in a frozen state cannot be modified, whereas objects in an unfrozen state can be modified as normal objects. Freezables provide observers with a Changed event that indicates any modifications to the object. When an object is frozen, it no longer needs to handle change notifications, which can improve its performance. Freezables can be shared across threads when they're frozen, but they can't be shared when they're unfrozen. Brushes, transformations, geometries, pens, and animations are some examples of freezable objects.
Objects in a 'frozen' state cannot be altered anytime. 
 
Let's consider a brush in a frozen state. What happens when we modify it? 
SolidColorBrush myBrush = new SolidColorBrush(Colors.Blue; 
myBrush.Freeze(); // Make the brush non-modifiable. 
myBrush.Color = Colors.Green; // Attempting to modify frozen brush

As shown below, it throws an InvalidOperationException :
 
InvalidOperation

Advertisement