Hello folks, I'm creating a custom virtualizing panel (different from virtualizingstackpanel), and I've come across with one little issue:

I need to get the visible vertical items from the viewport of a scrollviewer, given the viewport Height, and vertical offset.

I know how to do it when all the childs of the panel are fixed size(e.g Size(50,50)), but when childs have different sizes this gets kind of complicated.

I have an initial algorithm that will do the trick, but as I mentioned before it is only for fixed size childs.

Basically I need to find the indexes for the first and last item in the viewport Height of the panel.

csharp Code:
  1. //Child Size would vary in this case.
  2. firstVisibleItemIndex = (int) Math.Floor(_offset.Y / ChildSize) * childrenPerRow;
  3.            
  4. lastVisibleItemIndex = (int) Math.Ceiling((_offset.Y + _viewport.Height) / ChildSize) * childrenPerRow - 1;

Thanks in advance.