microsoft / microsoft/microsoft-ui-xaml
ItemsRepeater can recycle elements from a replaced DataTemplate into the new template’s pool
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
### Description
When an `ItemsRepeater` switches `ItemTemplate` and `Layout` in the same UI update, controls created by the old `DataTemplate` can be recycled into the new template’s recycle pool.
#### Suspected cause
ItemsRepeater::OnItemTemplateChanged resets existing elements before replacing the template wrapper, so they can return to the old template’s recycle pool.
However, when a subsequent Layout change clears remaining virtualized elements, the current template wrapper is already the new template. ItemTemplateWrapper::RecycleElement uses its current DataTemplate when selecting the recycle pool, so old-template elements can be put into the new template’s pool. When retrieved later, they retain the old template’s static property values.
### Why is this important?
This can cause incorrect visuals, layout corruption, incorrect accessibility properties, commands, event configuration, or any other template-defined state
### Steps to reproduce the bug
```xml
```
```
private void SetLayout()
{
Repeater.ItemTemplate = LayoutType == LayoutType.Square
? (DataTemplate)Resources["SquareTemplate"]
: (DataTemplate)Resources["WaterfallTemplate"];
}
```
### Actual behavior
Some controls remain realized with:
IgnoreDimensions == false
### Expected behavior
After changing to SquareTemplate, every realized ThumbnailControl should have:
```
IgnoreDimensions == true
```
### Screenshots
_No response_
### NuGet package version
2.4
### Windows version
Windows 11 (25H2): Build 26200
### Additional context
_No response_
Contributor guide
Research direction
Start with ItemsRepeater::OnItemTemplateChanged and ItemTemplateWrapper::RecycleElement, then reproduce the update sequence using the WaterfallTemplate and SquareTemplate XAML shown in the issue. Trace which template wrapper selects the recycle pool when ItemTemplate and Layout change together. Done means switching to SquareTemplate leaves every realized control with IgnoreDimensions set to true.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100