Performance Delay When Dynamically Populating WPF ItemsControl with Multiple ContentControls
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
In a WPF application, we are experiencing a significant performance bottleneck when dynamically populating an ItemsControl with a large number of ContentControl elements. The control is configured with a horizontal StackPanel as its ItemsPanelTemplate, and we populate it programmatically using a loop that adds approximately 2000 ContentControl instances. This results in a noticeable delay in UI rendering. The delay scales with the number of items added. We expect the UI to render quickly and the items should be displayed in view once the add button is clicked without delay.
This issue is reproducible in a minimal setup. I have attached a simple sample project for your reference, which demonstrates the rendering delay when dynamically adding a large number of ContentControl elements nearly 2000 to an ItemsControl.
Simple sample - [ItemsControl_Sample_WPF.zip](https://github.com/user-attachments/files/22072882/ItemsControl_Sample_WPF.zip)
### Reproduction Steps
1. Run the sample
2. Click the Add Items button to add 2000 content control instances
3. Observe the delay in UI rendering of the items.
### Expected behavior
The UI should render the items quickly, even when adding a large number of lightweight visual elements.
### Actual behavior
There is a noticeable delay in rendering 2000 items after the button click. The delay increases with the number of items added.
https://github.com/user-attachments/assets/142c4349-e847-4d77-8a4e-98e3fa2f336b
### Regression?
_No response_
### Known Workarounds
_No response_
### Impact
_No response_
### Configuration
### Other information
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.