Workaround for WPF Freezable bug? Workaround for WPF Freezable bug? wpf wpf

Workaround for WPF Freezable bug?


To workaround this .net bug, change all of the Solid Color Brushes in your code to be freezeable. For example

<SolidColorBrush x:Key="WindowBackground" Color="Black" />

should be changed to:

<SolidColorBrush po:Freeze="True" x:Key="WindowBackground" Color="Black" />. 

For more detailed instructions see here: How can WPF objects deriving from Freezable be frozen in XAML?.


I don't believe there is a work-around for this. In having to deal with this myself, from what I've read, WPF auto-freezes resources at creation. So anytime you try to use a DynamicResource on that resource you will get the freezable exception.

Here is a quote from the Microsoft Foundation Team on what is happening:

"WPF will freeze any freezables inside a style or template. Styles andtemplates can be used on multiple threads, and freezables can't unlessthey're frozen. We're currently considering extending this to anythingput inside Application.Resources, since that has the same threadingproblem... DynamicResource on a frozen freezable doesn't work, becausea frozen freezable potentially has multiple parents -- so it'sambiguous which parent we would search for the resource."


Every time it comes to buggy behaviour round about MVVM with ItemsControl and derived controls my first try is to disable VirtualizingStackPanel.

<ItemsControl VirtualizingStackPanel.IsVirtualizing="False" />

Just a try...