Closed ArnauPrat closed 7 months ago
Thanks for reporting. I have been able to reproduce your issue and am working on a fix.
New preview package with a fix is available: https://www.nuget.org/packages/VirtualizingWrapPanel/2.0.0-preview5
The stable release will follow soon.
Many thanks @sbaeumlisberger ! I'll try it out asap.
The stable version has just been released: https://www.nuget.org/packages/VirtualizingWrapPanel/2.0.0
Closing this now. Feel free to open a new issue if there is any problem.
Describe your issue Hi all, and first of all, thanks for maintaining this package.
I have a ListBox whose panel is a VirtualizingWrapPanel, similar to the following one, with item grouping. The ItemsPanelTemplate is set in code, because we have different templates based on different options, but I leave here the one the uses the VirtualizingWrapPanel
The issue is that when I call
ListBox.ScrollToViewModel
, it only works if the ViewModel is within the range of view models currently being cached. It works if:I've also tested different parameter combinations unsuccessfully (e.g. different CacheLengthUnit, VirtualizationMode, etc.)
I've dived bit into the code, and this is what I've found so far. Calling
ScrollToViewModel
on a ViewModel outside cache range (this is not called on items within range), ends up callingprotected override void BringIndexIntoView(int index)
https://github.com/sbaeumlisberger/VirtualizingWrapPanel/blob/f25434e1cc1996d3990eb75986842d9c8475dd98/src/VirtualizingWrapPanel/VirtualizingWrapPanel.cs#L374
which in turn calls
SetVerticalOffset
https://github.com/sbaeumlisberger/VirtualizingWrapPanel/blob/f25434e1cc1996d3990eb75986842d9c8475dd98/src/VirtualizingWrapPanel/VirtualizingPanelBase.cs#L384In such a method,
Offset
is set to the desired offset to scroll and measure is invalidated soMeasureOverride
is called.In
MeasureOverride
, the problem is that my VirtualizingWrapPanel has an ItemsOwner that is aIHierarichicalAndVirtualizationScrollInfo
https://github.com/sbaeumlisberger/VirtualizingWrapPanel/blob/f25434e1cc1996d3990eb75986842d9c8475dd98/src/VirtualizingWrapPanel/VirtualizingPanelBase.cs#L262so
Offset
gets overwritten at https://github.com/sbaeumlisberger/VirtualizingWrapPanel/blob/f25434e1cc1996d3990eb75986842d9c8475dd98/src/VirtualizingWrapPanel/VirtualizingPanelBase.cs#L282with the location of
groupItem
, which is not yet updated to the proper offset and contains the previous one.What I suspect is that
BringIndexIntoView
is not correctly implemented. According to documentation (https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.virtualizingpanel.bringindexintoview?view=windowsdesktop-7.0), this method should "When implemented in a derived class, generates the item at the specified index location and makes it visible.". The current implementation is not doing this, but deferring the creation of the desired items toMeasureOverride
(where things go wrong).Looking at
VirtualizingStackPanel
source code, which works properly, https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/VirtualizingStackPanel.cs,1576 the desired items are created and made visible right there.What do you think? Thanks for the help
Version Info 1.5.7 and 1.5.8 Net Framework 4.7.2 Microsoft Windows 10 Enterprise Version 10.0.19044 Build 19044