microsoft / microsoft/microsoft-ui-xaml
ItemsRepeater element recycling has bug for ItemsSource index 0
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
Using `ItemsRepeater` with `LinedFlowLayout` and checking recycling behaviour by `ElementPrepared` and `ElementClearing` event.
Two deferent element bound for index 0 of ItemsSource.
log
```
ElementPrepared Index:0 Ptr:3211120194192
ElementPrepared Index:0 Ptr:3211120194544
ElementPrepared Index:1 Ptr:3211120197360
ElementPrepared Index:2 Ptr:3211120199472
ElementPrepared Index:3 Ptr:3211120195952
ElementPrepared Index:4 Ptr:3211120195248
ElementPrepared Index:5 Ptr:3211120192432
ElementPrepared Index:6 Ptr:3211120196304
ElementPrepared Index:7 Ptr:3211120197008
ElementPrepared Index:8 Ptr:3211120197712
ElementPrepared Index:9 Ptr:3211120193136
```
```xaml
```
```cs
private void itemsRepeater_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args)
{
nint ptr = ((IWinRTObject)args.Element).NativeObject.ThisPtr;
Debug.WriteLine($"ElementPrepared Index:{args.Index} Ptr:{ptr.ToInt64()}");
}
private void itemsRepeater_ElementClearing(ItemsRepeater sender, ItemsRepeaterElementClearingEventArgs args)
{
nint ptr = ((IWinRTObject)args.Element).NativeObject.ThisPtr;
Debug.WriteLine($"ElementClearing Ptr:{ptr.ToInt64()}");
}
```
Next, scrolling down, down, down.., Two elements for Index 0 repeats Prepared and Clearing.
```
ElementPrepared Index:0 Ptr:3211131401264
ElementPrepared Index:0 Ptr:3211131409360
ElementClearing Ptr:3211131401264
ElementPrepared Index:0 Ptr:3211131401264
ElementClearing Ptr:3211131409360
ElementPrepared Index:0 Ptr:3211131409360
ElementClearing Ptr:3211131401264
ElementPrepared Index:0 Ptr:3211131401264
ElementClearing Ptr:3211131409360
ElementPrepared Index:0 Ptr:3211131409360
ElementClearing Ptr:3211131401264
ElementPrepared Index:0 Ptr:3211131401264
ElementClearing Ptr:3211131409360
ElementPrepared Index:0 Ptr:3211131409360
ElementClearing Ptr:3211131401264
ElementPrepared Index:0 Ptr:3211131401264
ElementClearing Ptr:3211131409360
ElementPrepared Index:0 Ptr:3211131409360
ElementClearing Ptr:3211131401264
ElementPrepared Index:0 Ptr:3211131401264
```
### Why is this important?
For apps like microsoft photo, ItemsRepeater's `ElementPrepared` and `ElementClearing` event timing is very important for managing thumbnail image.
### Steps to reproduce the bug
### Repro
[ItemsRepeaterBug01Repro.zip](https://github.com/user-attachments/files/23907846/ItemsRepeaterBug01Repro.zip)
1. Start Debug and Scroll down, down, down.
2. See Visual Studio Debug Output.
### Actual behavior
- Two Element bound for Index 0.
- Two elements for Index 0 repeats Prepared and Clearing.
### Expected behavior
Element for Index 0 behaves like for Index 1. Bound Single Item and dont repeat Prepared and Clearing.
### Screenshots
_No response_
### NuGet package version
WinUI 3 - Windows App SDK 1.8.3: 1.8.251106002
### Windows version
Windows 11 (24H2): Build 26100
### Additional context
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached ItemsRepeaterBug01Repro.zip and reproduce the issue using ItemsRepeater with LinedFlowLayout while watching the ElementPrepared and ElementClearing output. Trace the recycling path for ItemsSource index 0 and compare it with index 1. Done means index 0 has one element and does not repeatedly prepare and clear during scrolling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- desktop, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100