#175 – Freeze Graphical Objects That You Don’t Intend to Modify
January 3, 2011 Leave a comment
For performance purposes, it’s best to freeze graphical objects (e.g. brushes) if you don’t intend to modify them. You must also freeze an object if you intend to reference it from a thread other than the thread that created it.
You can freeze an object in code, using the Freeze method.
// SolidColorBrush, created in XAML, not frozen bool frozen = tealBrush.IsFrozen; // frozen = false if (tealBrush.CanFreeze) tealBrush.Freeze(); frozen = tealBrush.IsFrozen; // frozen = true
You can also freeze an object in XAML, when it is declared, with the addition of an XML namespace.
<Window x: <Window.Resources> <SolidColorBrush x: </Window.Resources>