Thursday, March 30, 2017

WPF Tip #7 - Freeze WPF Freezable Objects from Code

In Tip #6, we took a vector image resource and set it to Freeze = True in the XAML markup. Suppose that you need the resource to freeze at some point later in the application's execution. You can simply add this code to that point in the application:
If mySimpleImage.CanFreeze Then
    ' Makes the vector image frozen.
End If
Yes, I'm giving VB some love in today's tip.

Checking CanFreeze is necessary because not all Freezable objects can be frozen at every point in a WPF application's lifecycle. If Freeze() is called on an object that cannot currently be frozen, an exception will be thrown. Tags: ,,

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.