sbaeumlisberger / VirtualizingWrapPanel

Implementation of a comprehensive VirtualisingWrapPanel for WPF
MIT License
242 stars 33 forks source link

Scroll item into view by code #35

Closed rfberger closed 2 years ago

rfberger commented 2 years ago

Is there any possibitlity to scroll a known item into view by code? Ok, I'm a beginner using the VirtualizingWrapPanel and I try to find this, but without any success.

sbaeumlisberger commented 2 years ago

Of course. If you use a ListBox, ListView or the provided GridView you can use the ScrollIntoView method. see: https://docs.microsoft.com/de-de/dotnet/api/system.windows.controls.listbox.scrollintoview

rfberger commented 2 years ago

Thank you for answer. I use a ListView as container and I tried ScrollIntoView before, but I thought it doesn't work because a subequent call to listView.ItemContainerGenerator.ContainerFromItem(itemXY) returns always null for all items which are not in the acual windows. For items that are in the current windows it works. The same code sequence works well for e.g. a VirtualizingStackPanel from System.Windwos.Controls for all items as well for items which are "scrolled in". I'm sorry it appeared to me that the call to ScrollIntoView for VirtualizingWrapPanel doesn't work. It's probably a different problem.

sbaeumlisberger commented 2 years ago

Glad you were able to solve your initial issue.

Yes, the ContainerFromItem method returns null for all items which are not in the viewport or in the cache because there is no container for such items that could be returned.