Skip to content

Commit 652451e

Browse files
authored
Using freezable objects for enhanced performance (#3715)
* Create Optimizing-WPF-Rendering-Performance.md Added another file for Optimizing-WPF-Rendering-Performance * Create Freezable_Object_for_Enhanced_Performance.md
1 parent 8857b0a commit 652451e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[Home](..\README.md) > Using `Freezable` Objects for Enhanced Performance
2+
3+
---
4+
5+
# Using `Freezable` Objects for Enhanced Performance
6+
7+
## Background information
8+
9+
WPF provides the `Freezable` class for objects that can be made immutable to optimize performance, such as brushes, pens, and transforms.
10+
11+
## Setting Objects as `Freezable`
12+
13+
When an object is frozen, it becomes immutable, which reduces memory usage and allows WPF to optimize rendering.
14+
15+
```csharp
16+
SolidColorBrush myBrush = new SolidColorBrush(Colors.Blue);
17+
if (myBrush.CanFreeze)
18+
{
19+
myBrush.Freeze();
20+
}
21+
```
22+
23+
Frozen objects cannot be modified, so only freeze objects that don’t require changes.
24+
25+
## Benefits of Freezable Objects
26+
27+
Freezable objects improve rendering speed, especially for large visuals or repeated animations. This technique is particularly useful in complex UIs with many reused resources.

0 commit comments

Comments
 (0)