Hello Enrico,
Thank you for reaching out.
Based on the information you've provided, it looks like you are completely replacing the WordGroups collection every time you load more items.
// ...
if (IsGroupedByLetter)
WordGroups = Words?.ToObservableGroups(); // This creates a new collection
else
WordGroups = Words?.ToObservableGroups(Enums.GroupFor.WordType); // So does this
When you assign a new ObservableCollection to the ItemsSource of the CollectionView, the view has no choice but to discard its current state (including the scroll position) and render the new data from scratch.
In this case, I think it would be better to append the new items rather than replacing the entire collection.
Your second attempt has an issue: your WordGroup class inherits from List<Word>. The List<T> class does not notify the UI when items are added or removed. When you call existingGroup.Add(word), the CollectionView is unaware that the group's content has changed.
To fix this, you should change WordGroup to be an ObservableCollection<Word> itself, or a class that contains an ObservableCollection<Word>.
You could consider this approach:
- In
ReadMoreWords, after fetching the new words from your API, group only the new items. - Iterate through these newly created groups.
- For each new group:
- Check if a group with the same
Namealready exists in your mainWordGroupscollection. - If it does, add the new words to that existing group's collection of words.
- If it does not, add the entire new group to the
WordGroupscollection.
- Check if a group with the same
I hope this helps. Let me know if you have any further questions or need additional assistance.
If my suggestions resolve your issue, please consider marking this response as final.
Thank you.