Skip to content

Commit 77c8b3f

Browse files
authored
Reducing layout complexity (#3714)
* Create Optimizing-WPF-Rendering-Performance.md Added another file for Optimizing-WPF-Rendering-Performance * Create Reducing_Layout_Complexity.md * Rename Reducing_Layout_Complexity to Reducing_Layout_Complexity.md
1 parent 652451e commit 77c8b3f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/Reducing_Layout_Complexity.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Reducing Layout Complexity
2+
3+
## Background information
4+
5+
Complex layouts can slow down WPF performance, especially with nested controls or excessive use of `Grid` and `StackPanel`.
6+
7+
## Avoid Nested Grids and StackPanels
8+
9+
Overuse of nested layouts can create rendering bottlenecks. Try to simplify the structure or use a `UniformGrid` or `DockPanel` for simpler arrangements.
10+
11+
```xaml
12+
<!-- Instead of nesting multiple StackPanels, use a single DockPanel -->
13+
<DockPanel>
14+
<TextBlock Text="Header" DockPanel.Dock="Top" />
15+
<ListView DockPanel.Dock="Bottom" />
16+
</DockPanel>
17+
```
18+
19+
## Prefer Static Resources Over Dynamic Resources
20+
21+
Static resources are faster to load compared to dynamic ones. Use dynamic resources only if you need runtime changes in resource values.
22+
23+
```xaml
24+
<!-- Use StaticResource instead of DynamicResource for better performance -->
25+
<Style x:Key="ButtonStyle" TargetType="Button" BasedOn="{StaticResource BaseButtonStyle}" />
26+
```
27+
28+
> [!NOTE]
29+
> Dynamic resources are reevaluated each time they’re used, which may impact performance.

0 commit comments

Comments
 (0)